I added Logback to my Spring Boot project and it works when writing in files or standard output. Now I would like to send log emails, but if I try to configure the SMTPAppender, I get the following error:
Logging system failed to initialize using configuration from
'logback-spring.xml' java.lang.IllegalStateException: Logback
configuration error detected: ERROR in
ch.qos.logback.core.joran.action.AppenderAction - Could not create an
Appender of type [ch.qos.logback.classic.net.SMTPAppender].
ch.qos.logback.core.util.DynamicClassLoadingException: Failed to
instantiate type ch.qos.logback.classic.net.SMTPAppender ERROR in
ch.qos.logback.core.joran.spi.Interpreter#8:76 - ActionException in
Action for tag [appender]
ch.qos.logback.core.joran.spi.ActionException:
ch.qos.logback.core.util.DynamicClassLoadingException: Failed to
instantiate type ch.qos.logback.classic.net.SMTPAppender ERROR in
ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an
appender named [EMAIL]. Did you define it below instead of above in
the configuration file? ERROR in
ch.qos.logback.core.joran.action.AppenderRefAction - See
http://logback.qos.ch/codes.html#appender_order for more details. at
org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162)
at
org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
at
org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56)
at
org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115)
at
org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:308)
at
org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
at
org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at
org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at
org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73)
at
org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at
org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at
org.lh.cfpappserver.CfpAppServerApplication.main(CfpAppServerApplication.java:10)
Exception in thread "main" java.lang.IllegalStateException:
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not
create an Appender of type [ch.qos.logback.classic.net.SMTPAppender].
ch.qos.logback.core.util.DynamicClassLoadingException: Failed to
instantiate type ch.qos.logback.classic.net.SMTPAppender ERROR in
ch.qos.logback.core.joran.spi.Interpreter#8:76 - ActionException in
Action for tag [appender]
ch.qos.logback.core.joran.spi.ActionException:
ch.qos.logback.core.util.DynamicClassLoadingException: Failed to
instantiate type ch.qos.logback.classic.net.SMTPAppender ERROR in
ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an
appender named [EMAIL]. Did you define it below instead of above in
the configuration file? ERROR in
ch.qos.logback.core.joran.action.AppenderRefAction - See
http://logback.qos.ch/codes.html#appender_order for more details. at
org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:315)
at
org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
at
org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at
org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at
org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73)
at
org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at
org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
at
org.lh.cfpappserver.CfpAppServerApplication.main(CfpAppServerApplication.java:10)
Caused by: java.lang.IllegalStateException: Logback configuration
error detected: ERROR in
ch.qos.logback.core.joran.action.AppenderAction - Could not create an
Appender of type [ch.qos.logback.classic.net.SMTPAppender].
ch.qos.logback.core.util.DynamicClassLoadingException: Failed to
instantiate type ch.qos.logback.classic.net.SMTPAppender ERROR in
ch.qos.logback.core.joran.spi.Interpreter#8:76 - ActionException in
Action for tag [appender]
ch.qos.logback.core.joran.spi.ActionException:
ch.qos.logback.core.util.DynamicClassLoadingException: Failed to
instantiate type ch.qos.logback.classic.net.SMTPAppender ERROR in
ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an
appender named [EMAIL]. Did you define it below instead of above in
the configuration file? ERROR in
ch.qos.logback.core.joran.action.AppenderRefAction - See
http://logback.qos.ch/codes.html#appender_order for more details. at
org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162)
at
org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
at
org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56)
at
org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115)
at
org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:308)
... 13 more
This is my configuration in logback-spring.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<asynchronousSending>false</asynchronousSending>
<smtpHost>smtp.gmail.com</smtpHost>
<to>my email</to>
<from>my email</from>
<username>xxx</username>
<password>xxx</password>
<subject>%logger{20} - %m</subject>
<layout class="ch.qos.logback.classic.html.HTMLLayout"/>
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<bufferSize>1</bufferSize>
</cyclicBufferTracker>
<starttls>true</starttls>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="org.lh.cfpappserver.util.StdOutFilter"/>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="EMAIL"/>
<appender-ref ref="STDOUT"/>
</root>
</configuration>
What's wrong in my configuration preventing the application to start?
Related
I'm trying to create a custom log file for my flow in Nifi; to achieve that I want to use the logback filters.
In my logback.conf I added a new appender called LLAB_FILE which filters the log message by its content:
<appender name="LLAB_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${org.apache.nifi.bootstrap.config.log.dir}/llab-transform.log</file>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<expression>return message.contains("LLAB_TRANSFORM");</expression>
</evaluator>
<OnMismatch>DENY</OnMismatch>
<OnMatch>ACCEPT</OnMatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${org.apache.nifi.bootstrap.config.log.dir}/llab-transform_%d.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<immediateFlush>true</immediateFlush>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%date~%level~%msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="LLAB_FILE"/>
</root>
However this configuration gives the following error when Nifi starts:
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org/codehaus/janino/ScriptEvaluator
at ch.qos.logback.core.boolex.JaninoEventEvaluatorBase.start(JaninoEventEvaluatorBase.java:57)
at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:161)
at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
at org.apache.nifi.bootstrap.RunNiFi.<init>(RunNiFi.java:134)
at org.apache.nifi.bootstrap.RunNiFi.main(RunNiFi.java:231)
Caused by: java.lang.ClassNotFoundException: org.codehaus.janino.ScriptEvaluator
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 20 more
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/janino/ScriptEvaluator
at ch.qos.logback.core.boolex.JaninoEventEvaluatorBase.start(JaninoEventEvaluatorBase.java:57)
at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.end(NestedComplexPropertyIA.java:161)
at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
at org.apache.nifi.bootstrap.RunNiFi.<init>(RunNiFi.java:134)
at org.apache.nifi.bootstrap.RunNiFi.main(RunNiFi.java:231)
Caused by: java.lang.ClassNotFoundException: org.codehaus.janino.ScriptEvaluator
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
How can I fix this? I don't want to process the logs throw a nifi's flow.
Thanks,
Temp
http://logback.qos.ch/manual/filters.html#JaninoEventEvaluator
JaninoEventEvaluator requires the Janino library.
Please see the corresponding section of the setup document.
actually any evaluator requires additional library
Recently I've been working with logback and everything was going smooth until I tried to use Marker Filters together with the conditional xml tags.
What I wanted to do is to have a marker filtering system that would, depending on a property previously set, choose the adequate marker filters for my appenders.
My current code is bellow:
<configuration scan="true" scanPeriod="30 seconds">
<if condition='property("severityLevel").equals("SEVERITY-2")'>
<then>
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
<Marker>SEVERITY-1</Marker>
<OnMatch>DENY</OnMatch>
</turboFilter>
</then>
</if>
<!-- Console Appender -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level - ${appName} - %marker - %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</root>
</configuration>
The property severityLevel comes from the configurator property that I set before initializing the logger:
LoggerContext aLoggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator aConfigurator = new JoranConfigurator();
aConfigurator.setContext(aLoggerContext);
aLoggerContext.reset();
aLoggerContext.putProperty(APPLICATION_NAME, config.getApplicationName());
aLoggerContext.putProperty(LOG_MAX_FILE_SIZE, config.getLogMaxFileSize().toString());
aLoggerContext.putProperty(LOG_KEEP_FOR_DAYS, config.getLogKeepForDays().toString());
aLoggerContext.putProperty("severityLevel", "SEVERITY-2");
System.out.println(aLoggerContext.getProperty("severityLevel"));
try
{
aConfigurator.doConfigure(FileUtils.cleanPath(FileUtils.determineServletRealPath(""), false) + LOGBACK_CONFIGURATION_FILE_PATH);
}
catch (JoranException e)
{
StatusPrinter.printIfErrorsOccured(aLoggerContext);
throw e;
}
The expected behaviour would be that only SEVERITY-2 level messages would be logged. Instead, I keep getting all messages.
If I take the If condition out of the logback.xml file it will work fine but I still need to have another condition for a SEVERITY-3 in which both level 2 and level 1 will be denied and therefore I would need the If condition.
Some status messages from the logs:
|-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
|-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
|-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [vfs:/Applications/wildfly-10.1.0.Final/standalone/deployments/mw-file-extractor.war/WEB-INF/classes/logback.xml]
|-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList#6b14b260 - URL [vfs:/Applications/wildfly-10.1.0.Final/standalone/deployments/mw-file-extractor.war/WEB-INF/classes/logback.xml] is not of type file
|-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
|-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [vfs:/Applications/wildfly-10.1.0.Final/standalone/deployments/mw-file-extractor.war/WEB-INF/classes/logback.xml]
|-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 30 seconds
|-ERROR in ch.qos.logback.core.joran.conditional.IfAction - Could not find Janino library on the class path. Skipping conditional processing.
|-ERROR in ch.qos.logback.core.joran.conditional.IfAction - See also http://logback.qos.ch/codes.html#ifJanino
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
|-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
|-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
|-INFO in ch.qos.logback.classic.joran.JoranConfigurator#726fa157 - Registering current configuration as safe fallback point
Does anyone know what am I doing wrong?
Found out, with the help of #Ceki and Logback debug messages that I was missing the Janino library for the use of conditionals.
Adding both janino-3.0.8.jar and commons-compiler-3.0.8.jar fixed the issue.
I have a question about this, i am going send the logback logs to rabbit, and i use spring-rabbit, as i need to send the data with json format, so i used LoggingEventCompositeJsonEncoder, here are my configuration
<appender name="AMQP" class="org.springframework.amqp.rabbit.logback.AmqpAppender">
<!--<layout>-->
<!--<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>-->
<!--</layout>-->
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<pattern>
<pattern>
{ "level": "%level" }
</pattern>
</pattern>
</encoder>
<host>127.0.0.1</host>
<port>5672</port>
<username>guest</username>
<password>guest</password>
<routingKeyPattern>testroute</routingKeyPattern>
<exchangeName>logs</exchangeName>
<declareExchange>true</declareExchange>
<generateId>true</generateId>
<charset>UTF-8</charset>
<durable>true</durable>
<deliveryMode>PERSISTENT</deliveryMode>
</appender>
but when i start the application, i got the error as below :
java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.spi.Interpreter#16:88 - no applicable action for [encoder], current ElementPath is [[configuration][appender][encoder]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter#18:22 - no applicable action for [pattern], current ElementPath is [[configuration][appender][encoder][pattern]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter#19:26 - no applicable action for [pattern], current ElementPath is [[configuration][appender][encoder][pattern][pattern]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:81)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:59)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115)
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:303)
at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
That's correct the org.springframework.amqp.rabbit.logback.AmqpAppender is a AppenderBase extension, not an OutputStreamAppender which supports that encoder option.
However I'm pretty sure we can add support for it and instead of raw msgBody.getBytes() call already this.encoder.encode(event).
The JIRA on the matter: https://jira.spring.io/browse/AMQP-760.
I am new with logging, and using logback for my project. I create the logger configuration file logback.xml at put at the class path in maven project this is at resource root folder. Following is my configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextName>It-Support</contextName>
<timestamp key="timeFormat" datePattern="yyyyMMdd'T'HHmmss" timeReference="contextBirth" />
<property resource="properties/logback-variables.properties" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${file.record}/log.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>5MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>6</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appernder-ref ref="STDOUT" />
<!-- <appernder-ref ref="ROLLING" /> -->
</root>
</configuration>
In my java code, i am using logger.info, logger,error etc methods for print the information on console, but when the code is run, logger not able to print the information at eclipse console. My java code as below:
private Logger logger = LoggerFactory.getLogger(MachineController.class);
public String machinesList(Model model) {
logger.info("call machinesList controller GET");
---------------------
}
When i start the tomcat, the server print below logs:
SEVERE: The web application [/it-support] created a ThreadLocal with key of type [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1] (value [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1#31924c14]) and a value of type [com.microsoft.sqlserver.jdbc.ActivityId] (value [b1d32454-45c4-4684-9339-b12835b563d2-0]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
15:13:00,945 |-INFO in ch.qos.logback.classic.LoggerContext[It-Support] - Could NOT find resource [logback.groovy]
15:13:00,946 |-INFO in ch.qos.logback.classic.LoggerContext[It-Support] - Could NOT find resource [logback-test.xml]
15:13:00,946 |-INFO in ch.qos.logback.classic.LoggerContext[It-Support] - Found resource [logback.xml] at [jar:file:/D:/tommy8/webapps/it-support-web/WEB-INF/lib/it-support-common-0.0.1-SNAPSHOT.jar!/logback.xml]
15:13:01,004 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList#20b42477 - URL [jar:file:/D:/tommy8/webapps/it-support-web/WEB-INF/lib/it-support-common-0.0.1-SNAPSHOT.jar!/logback.xml] is not of type file
15:13:01,078 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
15:13:01,101 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [It-Support]
15:13:01,101 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Using context birth as time reference.
15:13:01,107 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Adding property to the context with key="timeFormat" and value="20150204T151300" to the LOCAL scope
15:13:01,111 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:13:01,119 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
15:13:01,165 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:13:01,285 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:13:01,291 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ROLLING]
15:13:01,361 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
15:13:01,365 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern log-%d{yyyy-MM-dd}.%i.log for the active file
15:13:01,371 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP#28345639 - The date pattern is 'yyyy-MM-dd' from file name pattern 'log-%d{yyyy-MM-dd}.%i.log'.
15:13:01,371 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP#28345639 - Roll-over at midnight.
15:13:01,372 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP#28345639 - Setting initial period to Thu Jan 08 20:09:57 IST 2015
15:13:01,375 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:13:01,381 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ROLLING] - Active log file name: logs/log.log
15:13:01,381 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ROLLING] - File property is set to [logs/log.log]
15:13:01,384 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
15:13:01,394 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter#30:33 - no applicable action for [appernder-ref], current ElementPath is [[configuration][root][appernder-ref]]
15:13:01,394 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:13:01,397 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator#63f55760 - Registering current configuration as safe fallback point
It's "appender-ref", not "appernder-ref".
That is why your appender is not registered with the root-logger:
15:13:01,394 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter#30:33 - no applicable action for [appernder-ref], current ElementPath is [[configuration][root][appernder-ref]]
Using logback-1.0.13.jar and JDK 1.6u34.
I have a Java web app (WAR) with the following WEB-INF/classes/logback.xml:
<configuration debug="true" scan="true" scanPeriod="5 minutes">
<appender name="logManager-smtpAppender" class="ch.qos.logback.classic.net.SMTPAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<asynchronousSending>false</asynchronousSending>
<sessionViaJNDI>true</sessionViaJNDI>
<jndiLocation>java:comp/env/mail/Session-local</jndiLocation>
<subject>%logger{20} - %m</subject>
<layout class="ch.qos.logback.classic.html.HTMLLayout"/>
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<bufferSize>25</bufferSize>
</cyclicBufferTracker>
</appender>
<root level="ALL">
<appender-ref ref="logManager-smtpAppender" />
</root>
</configuration>
And the following ${TOMCAT_HOME}/conf/context.xml (global context.xml for all web apps):
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource
name="mail/Session-local"
auth="Container"
type="javax.mail.Session"
mail.smtp.host="my.smtp.server"
mail.user="smtp_user"
mail.password="smtp_password"
mail.transport.protocol="smtp"
mail.smtp.auth="true"
mail.smtp.port="25"
mail.smtp.starttls.enable="true"
/>
</Context>
And have the Java Mail API 1.4.3 (which I have verified contains a javax.mail.Authenticator class) on my runtime classpath at WEB-INF/lib/javax-mail-1.4.3.jar). I also have it in Tomcat's lib directory (${TOMCAT_HOME}/lib).
And am getting the following stack trace:
13:34:09,178 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
13:34:09,179 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
13:34:09,181 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/home/myuser/sandbox/dsi/workbench/tomcat/6.0.32/apache-tomcat-6.0.32/webapps/myapp/WEB-INF/classes/logback.xml]
13:34:09,469 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeFilter scanning period to 5 minutes
13:34:09,470 |-INFO in ReconfigureOnChangeFilter{invocationCounter=0} - Will scan for changes in [[/home/myuser/sandbox/dsi/workbench/tomcat/6.0.32/apache-tomcat-6.0.32/webapps/myapp/WEB-INF/classes/logback.xml]] every 300 seconds.
13:34:09,470 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Adding ReconfigureOnChangeFilter as a turbo filter
13:34:11,782 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.net.SMTPAppender]
13:34:11,830 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [logManager-smtpAppender]
13:34:11,939 |-INFO in ch.qos.logback.classic.net.SMTPAppender[logManager-smtpAppender] - Looking up javax.mail.Session at JNDI location [java:comp/env/mail/Session-local]
13:34:11,992 |-ERROR in ch.qos.logback.classic.net.SMTPAppender[logManager-smtpAppender] - Failed to obtain javax.mail.Session from JNDI location [java:comp/env/mail/Session-local]
13:34:11,992 |-ERROR in ch.qos.logback.classic.net.SMTPAppender[logManager-smtpAppender] - Failed to obtain javax.mail.Session. Cannot start.
13:34:11,993 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ALL
13:34:11,996 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [logManager-smtpAppender] to Logger[ROOT]
13:34:11,997 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
13:34:12,000 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator#63220fd1 - Registering current configuration as safe fallback point
13:39:49,988 |-WARN in ch.qos.logback.classic.net.SMTPAppender[logManager-smtpAppender] - Attempted to append to non started appender [logManager-smtpAppender].
13:39:49,988 |-WARN in ch.qos.logback.classic.net.SMTPAppender[logManager-smtpAppender] - Attempted to append to non started appender [logManager-smtpAppender].
13:39:50,598 |-WARN in ch.qos.logback.classic.net.SMTPAppender[logManager-smtpAppender] - Attempted to append to non started appender [logManager-smtpAppender].
13:39:51,275 |-WARN in ch.qos.logback.classic.net.SMTPAppender[logManager-smtpAppender] - Attempted to append to non started appender [logManager-smtpAppender].
13:39:51,833 |-WARN in ch.qos.logback.classic.net.SMTPAppender[logManager-smtpAppender] - Attempted to append to non started appender [logManager-smtpAppender].
Any ideas as to why Logback can't retrieve my JNDI Mail Session from Tomcat's context.xml? This is preventing the SMTPAppender from starting and being able to log messages. Thanks in advance!
First, don't put the mail JAR in both locations, but in Tomcat's lib folder. If you are using Maven, use provided scope for the corresponding <dependency /> to not package it in the WAR.
Second, do you have a <resource-ref /> element for the mail session in your web.xml? If not, look here for a sample.
Another alternative is to make the session <resource /> global (in server.xml) and link to it from the context.xml, as described here.
HTH,
Jukka