wildfly10 - filter multiple values - filter

i want to filter my wildfly10 logfile.
I get error messages like this:
28 Feb 2019 11:22:43,906 ERROR [com.ser.sedna.services.transfer.xf.util.InvocationContextImpl] (default task-6) Exception caught in webservice method.: SECU0015I: The caller **** does not have the abacRead permission on...
My configuration looks like this:
<size-rotating-file-handler name="FILE" autoflush="true">
<level name="INFO"/>
<filter-spec value="not(match("WFLYEJB0043|SECU0015I|abacRead"))"/>
<formatter>
<pattern-formatter pattern="%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file path="*****/server.log"/>
<rotate-size value="15M"/>
<max-backup-index value="10"/>
<append value="true"/>
</size-rotating-file-handler>
The filter i set does not work. What am i doing wrong?

Related

Application not writing logs on when log file rotates

My app is using spring log4j2 and uses slf4j api to write log to separate log file "application.log". This app gets deployed to tomcat v8 along with other apps. All app share common log4j2 configuration and writes to common logfile 'application.log'. We have a log rotation policy of 250 mb and when the log file rotates the logs are not written to the logfile surprising only one app among all the app is able to write to the log file. I'm able to reproduce this locally too. Can you please help in fixing this issue.
The other
Please find the log4j2.xml config below.
JAR VERSIONS
slf4j-api 1.7.21
log4j-slf4j-impl 2.5
log4j-api 2.5
log4j-core 2.5
log4j-web 2.5
Log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration name="api-config" status="trace" monitorInterval="30">
<Properties>
<Property name="logdir">/Users/kramesan/microservices-config/logs</Property>
</Properties>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%X{_requestId} %X{authToken} %X{urlEmployeeId} %X{urlCompanyId} [%X{authEmplIds}] [%X{authCompanyIds}] %d{yyy
y-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/>
</Console>
<RollingFile name="ApplicationLogRollingFile" fileName="${logdir}/application.log"
filePattern="${logdir}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
<JSONLayout locationInfo="true" complete="true" compact="true" eventEol="true" properties="true" />
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB" />
</Policies>
<DefaultRolloverStrategy max="20" />
</RollingFile>
<RollingFile name="AuditLogRollingFile" fileName="${logdir}/audit/api-audit.log"
filePattern="${logdir}/audit/$${date:yyyy-MM}/api-audit-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<Pattern>%X{_requestId} %X{authToken} %X{urlEmployeeId} %X{urlCompanyId} [%X{authEmplIds}] [%X{authCompanyIds}] %m%n</Pattern>
</PatternLayout>
<!-- JSONLayout locationInfo="true" complete="true" compact="true" eventEol="true" properties="true" -->
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB" />
</Policies>
<DefaultRolloverStrategy max="20" />
</RollingFile>
<Async name="ApplicationLogAsync" bufferSize="262144">
<AppenderRef ref="ApplicationLogRollingFile"/>
</Async>
<Async name="AuditLogAsync" bufferSize="262144">
<AppenderRef ref="AuditLogRollingFile"/>
</Async>
</Appenders>
<Loggers>
<!-- All the 3rd Party frameworks -->
<Logger name="org.springframework" level="warn" />
<Logger name="org.hibernate" level="warn" />
<!-- common package name for all the business application level code -->
<Logger name="com.trinet" level="info" />
<!-- Audit Loggger This is used for spring aspect to log before and after execution -->
<Logger name="AuditLogger" level="info">
<AppenderRef ref="AuditLogAsync" />
</Logger>
<Root level="info">
<AppenderRef ref="ApplicationLogAsync" />
</Root>
</Loggers>
</Configuration>
Please, edit your Logger name. Logger name property needs package path.
AS-IS
...
<Logger name="AuditLogger" level="info">
...
TO-BE
...
<Logger name="com.foo.bar.AuditLogger" level="info" additivity="false">
...
or
...
<Logger name="com.foo.bar.*" level="info" additivity="false">
...
I think you'd better write property additivity Because your Logger works two times com.foo.bar.AuditLogger Logger and Root Logger. so you additivity to false then it works each.
reference link : Additivity

Why don't System.out.printlin, and Logger work in my websocket?

Can anyone tell me why why nothing I log from my class, and nothing I print using System.out.println, shows up in the log or on the console?
My websocket endpoint class is named
"org.america3.websockets.sockets.WSEndPoint"
I know it successfully deploys to Wildfly in a .WAR package (inside an .EAR package), because my html page confirms it that it opens a websocket object.
From my endpoint class:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
#Transient
final Logger logger = LoggerFactory.getLogger(WSEndpoint.class);
In my standalone-full.xml
<subsystem xmlns="urn:jboss:domain:logging:3.0">
...
<console-handler name="CONSOLE">
<level name="INFO"/>
<formatter>
<named-formatter name="COLOR-PATTERN"/>
</formatter>
</console-handler>
...
<console-handler name="MY-CONSOLE" autoflush="true">
<formatter>
<named-formatter name="MY-PATTERN"/>
</formatter>
<target name="System.out"/>
</console-handler>
...
<console-handler name="TEST-HANDLER">
<level name="INFO"/>
<formatter>
<named-formatter name="TEST-PATTERN"/>
</formatter>
</console-handler>
...
<periodic-rotating-file-handler name="FILE" autoflush="true">
<formatter>
<named-formatter name="PATTERN"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
...
<logger category="org.america3" use-parent-handlers="false">
<level name="ALL"/>
<handlers>
<handler name="TEST-HANDLER"/>
</handlers>
</logger>
...
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
...
<formatter name="PATTERN">
<pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
</formatter>
<formatter name="COLOR-PATTERN">
<pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
</formatter>
<formatter name="MY-PATTERN">
<pattern-formatter pattern="MeMeMe%s%n"/>
</formatter>
<formatter name="TEST-PATTERN">
<pattern-formatter pattern="*** %s%n"/>
</formatter>
...
</subsystem>
I'm not sure if this is the only answer, but it worked.
Originally I packaged my Endpoint in the same jar I used to deploy my Session beans. And made the jar a module of my ear package. The Session Beans deployed and logged correctly. The Endpoint didn't.
Then I redeployed my endpoint under META-INF/classes of a war package as a second ear module, and it worked as it should.
I'm sure I read somewhere that an Endpoint could be deployed in the ear package along with other classes. So I'm not sure if maybe I fixed some other error I didn't originally -- that was fixed when I repackaged the app.
But for now it works as it should, so I'll stay with keeping my Endpoint in the war META-INF/classes directory.

log4j2 TcpSocketServer does not replace any "{}" in message

I have a spring boot(v1.5.4) web application which use log4j-2.7 for logging.
It works well when write log message to file or console, but when send message to TcpSocketServer, the log server just output the message without the "{}" formatting. for example, for this code:
logger.info("Request from [{}] to [{}]", ipInfo, reqPath);
The RollingfileAppender and ConsoleAppender will output:
INFO 2017-07-06 16:46:07,929 [127.0.0.1][/senten/align] AuthFilter (http-nio-8180-exec-2) Request from [127.0.0.1] to [/senten/align]
But the SocketAppender just ouput:
INFO 2017-07-06 16:46:07,929 [127.0.0.1][/senten/align] AuthFilter (http-nio-8180-exec-2) Request from [{}] to [{}]
This is my config with SocketAppenders in log4j.xml
<Appenders>
<Socket name="socket" host="127.0.0.1" port="9898">
<SerializedLayout />
</Socket>
........
</Appenders>
This is my config file log4j2-socket.xml for TcpSocketServer:
<Configuration status="WARN">
<Appenders>
<RollingFile name="default" fileName="Logs/app.log"
filePattern="Logs/${date:yyyy-MM}/app-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%-5p %d [%X{ip}][%X{reqPath}] %c{1} (%t) %m %ex%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval = "30" modulate="true"/>
<SizeBasedTriggeringPolicy size="200 MB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="default" level="DEBUG" />
</Root>
</Loggers>
</Configuration>
And, I use this command for start TcpSocketServer:
java -classpath log4j-core-2.7.jar:log4j-api-2.7.jar:jcommander-1.48.jar org.apache.logging.log4j.core.net.server.TcpSocketServer -p 9898 -c log4j2-socket.xml
Does anybody know what's going wrong here, and how to fix it? Thanks!
I file a bug on JIRA of log4j2. A good guy helps me to resolve this problem.
The solution is update to log4j-2.8.2, and adding this arguments for starting TcpSocketServer:
--classes java.util.Collections$UnmodifiableMap --classes java.util.HashMap

Redirecting feign & ribbon logs to log4j2

I currently use spring cloud netflix with log4j2. The log4j2 configuration comes from the xml in the classpath. When I run the app, I see that the feign & ribbon logs are not being redirected to the logger specified in the configuration. I have configured log for com.netflix.ribbon & feign packages to be logged at debug level.
However, log configured for spring is properly redirecting to the specified appender, ribbon & feign are not.
I am using gradle with spring-boot-starter-logging ignored & added spring-boot-starter-log4j2 in as part of my build.
I see that feign has a way by which we can configure slf4j, but since we use annotation driven feign support, I cant configure the feign to use slf4j for logging.
Any help is appreciated.
My log4j2.xml looks some what like
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="log-path">logs</Property>
<Property name="log-fileName">test</Property>
</Properties>
<Appenders>
<Console name="console-log" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
<RollingFile name="trace-log" fileName="${log-path}/${log-fileName}-trace.log" filePattern="${log-path}/${log-fileName}_trace-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>
<RollingFile name="error-log" fileName="${log-path}/${log-fileName}-error.log" filePattern="${log-path}/${log-fileName}_error-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<logger name="org.springframework" level="trace" additivity="false">
<AppenderRef ref="trace-log" />
</logger>
<logger name="feign" level="trace" additivity="false">
<AppenderRef ref="trace-log" />
</logger>
<logger name="com.netflix.ribbon" level="trace" additivity="false">
<AppenderRef ref="trace-log" />
</logger>
<Root level="info">
<AppenderRef ref="console-log"></AppenderRef>
<AppenderRef ref="error-log" level="ERROR"/>
</Root>
</Loggers>
</Configuration>
PS: The reason for debugging feign/ribbon is to understand a weird feign behavior between two different machines in our micro services setup
Looking at Spring Cloud's FeignClientFactoryBean shows that you can optionally autowire a bean of type feign.Logger.Level. Try registering such a bean in your #Configurationusing
#Bean
public feign.Logger.Level feignLoggerLevel() {
return feign.Logger.Level.FULL;
}
#jensfischerhh's answer would fix many cases but looks mistakenly missed one thig.
You need to config feign generated class's logger level with feignLoggerLevel Bean.
Both config must be exist together.
related doccument in spring-cloud-netflix
bean config ( in #Configuration annotated class )
#Bean
public feign.Logger.Level feignLoggerLevel() {
return feign.Logger.Level.FULL;
}
log config
</Configuration>
<Loggers>
<logger name="your.feign-interface-package" level="trace">
</Loggers>
</Configuration>

Spring Boot logging pattern

I have a problem with configuration on Logback in a Spring Boot application. I want my consoleAppender to look like the default Spring Boot console appender. How to inherit pattern from Spring Boot default console appender?
Below is my consoleAppender configuration
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern class="org.">
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
Once you have included the default configuration, you can use its values in your own logback-spring.xml configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<!-- use Spring default values -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
…
</configuration>
You can find Spring Boot logback console logging pattern in defaults.xml file:
spring-boot-1.5.0.RELEASE.jar/org/springframework/boot/logging/logback/defaults.xml
Console pattern:
<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx
</Pattern>
</layout>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
If you are using application.yml for your config, you can set the logging pattern this way:
logging:
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} | %-5level | %logger{1.} | %msg%n"
level:
org.springframework: WARN
com.ulisesbocchio.jasyptspringboot: WARN
com.example.test: DEBUG
You can override the logging level on the command line. For example:
$ java -Dlogging.level.com.example.test=TRACE -jar my-example.jar
It's been some time since this question was asked but since I had the problem myself recently and couldn't find an answer I started digging a bit deeper and found a solution that worked for me.
I ended up using the debugger and take a look at the default appenders attached to the logger.
I found this pattern to be working as desired for me:
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p 18737 --- [%t] %-40.40logger{39} : %m%n%wEx</pattern>
EDIT: The pattern is not entirely correct, I saw that runtime some values had already been instantiated (in this case 18737 ---) i will look into the proper variable to substitute there. It does contain the format for fixed length columns though
EDIT 2: Ok, I took another look at the debugger contents. This you can also do yourself by looking at the contents of a logger instance:
Debugger(eclipse) Logger Contents
So I ended up using the pattern used in the consoleAppender:
%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(18971){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx
As can be seen here:
Debugger: detailed contents of the encoder pattern
Logging pattern can be configured using application.properties file
Example :
# Logging pattern for the console
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} - %msg%n
You can use below pattern :
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${sys:PID} --- [%15.15t] %-40.40logger{1.} : %m%n%wEx
Note that you can also customize the imported properties.
But beware that at least with spring boot 1.4.3 if you want to customize the properties imported from the defaults.xml, then the customization should be placed BEFORE the include.
For example this customizes the priority to 100 character wide:
<configuration scan="true">
<property name="LOG_LEVEL_PATTERN" value="%100p" />
<!-- use Spring default values -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
</layout>
</appender>
<logger name="hu" level="debug" additivity="false">
<appender-ref ref="CONSOLE" />
</logger>
<root level="warn">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
But this is NOT:
<configuration scan="true">
<!-- use Spring default values -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<property name="LOG_LEVEL_PATTERN" value="%100p" />
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
</layout>
</appender>
<logger name="hu" level="debug" additivity="false">
<appender-ref ref="CONSOLE" />
</logger>
<root level="warn">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
For those who'd like to use Łukasz Frankowski's answer (which looks like the cleanest solution here), but in a groovy version, the "problematic" {$PID:- } part can be expanded like in the following:
logback-spring.groovy
import ch.qos.logback.classic.PatternLayout
import ch.qos.logback.core.ConsoleAppender
import org.springframework.boot.logging.logback.ColorConverter
import org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter
import org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter
import static ch.qos.logback.classic.Level.INFO
conversionRule("clr", ColorConverter)
conversionRule("wex", WhitespaceThrowableProxyConverter)
conversionRule("wEx", ExtendedWhitespaceThrowableProxyConverter)
appender("STDOUT", ConsoleAppender) {
layout(PatternLayout) {
def PID = System.getProperty("PID") ?: ''
pattern = "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx"
}
}
root(INFO, ["STDOUT"])
This worked for me, adding following line to resources/log4j2.properties file
appender.console.layout.pattern = %d{ISO8601} - info: %msg%n ( your custom pattern goes here )
The spring documentation has an example of the logback.xml that defines the default.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>

Resources