log4j.rootCategory field in log4j.properties can have 4 different values, namely: DEBUG, WARN, INFO and ERROR.
Can you tell me which is most suitable for which cases?
From the least severe to the most one:
ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF
If you choose one of them log4j will generate all messages of that type and of more severe type.
Purposes:
ALL: generates all messages*
DEBUG: debug messages
INFO: information that aren't problems
WARN: not error but something that could cause a future error
ERROR: something went wrong, a problem that the application manages, the application could be stopped or not, usually must be reported
FATAL: an error that crashes the application
OFF: generates no messages*
(*) these are only keywords; for these categories there are no methods all(msg) and off(msg), like we have error(msg) or debug(msg).
Usually
during development I set
logging on file to ALL or DEBUG
when deployed I set
logging on file to INFO or WARN
logging via email to ERROR
Related
I have set testLogging.showStandardStreams = true in build.gradle, but it is printing log message from all classes, including Spring boot classes. But I want only log statements written in my test classes should print.
If I have package called org.example.test, can I set somewhere the package in build.gradle, or do we have some other property?
Currently it print something like this and I don't want first 2 lines:
2021-10-11 18:35:05.575+0530 [] 2424#HOSTNAME [Test worker] INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring TestDispatcherServlet ''
2021-10-11 18:35:05.574+0530 [] 2424#HOSTNAME [org.springframework.amqp.rabbit.RabbitListenerEndpointContainer#0-299] WARN org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer - Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
2021-10-11 18:35:05.604+0530 [] 2424#HOSTNAME [Test worker] INFO com.exmple.test - --------S--------
Please make sure to check gradle offical doc for more about logger.
There are 6 types of logs and you can add parameter to get it:
ERROR for Error messages ( will always be shown )
QUIET for Important information messages ( add -q )
WARNING for Warning messages ( add -w )
LIFECYCLE for Progress information messages
INFO for Information messages (add -i )
DEBUG for Debug messages (add -d )
For example if you want to get the debug , you type gradle build -d and so on .
I am working on a project using Intellij IDEA Community, so I am using Jetty Runner to deploy my web application in localhost, everything is working ok, but I want to configure logs regarding Jetty, at server startup I see this kind of log :
14:50:20.516 [main] DEBUG o.eclipse.jetty.webapp.WebAppContext - isSystemResource==false org.springframework.expression.spel.ast.OpDec jar:file:/C:/Mario/development/spring/spring5/workspace/springsecurity/chapter02/chapter02.00-calendar/build/exploded/WEB-INF/lib/spring-expression-4.3.11.RELEASE.jar!/org/springframework/expression/spel/ast/OpDec.class
14:50:20.516 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - WAP webapp loaded class org.springframework.expression.spel.ast.OpDec
14:50:20.516 [main] DEBUG o.eclipse.jetty.webapp.WebAppContext - isSystemResource==false org.springframework.expression.spel.ast.OperatorNot jar:file:/C:/Mario/development/spring/spring5/workspace/springsecurity/chapter02/chapter02.00-calendar/build/exploded/WEB-INF/lib/spring-expression-4.3.11.RELEASE.jar!/org/springframework/expression/spel/ast/OperatorNot.class
14:50:20.517 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - WAP webapp loaded class org.springframework.expression.spel.ast.OperatorNot
1
I want to change the granularity from DEBUG to info regarding jetty server.
Put a jetty-logging.properties file in your resources folder and configure the logging there:
# Configure for System.err output
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
# Configure StdErrLog to log all jetty namespace at default of WARN or above
org.eclipse.jetty.LEVEL=INFO
More info here: https://www.eclipse.org/jetty/documentation/9.4.x/configuring-logging.html
Please have a look at the image below.
I am running Log4J but using the TimeAndSizeRollingFileAppender provided from http://www.simonsite.org.uk/ .
According to the site it should be a good version that is used by many companies.
What could be the cause for all these processes running independently?
I am running a WAR file, and I have this configuration:
# DEBUG < INFO < WARN < ERROR < FATAL ==> DEBUG SHOWS ALL, WARN will show WARN, ERROR and FATAL
# Variable
momomo.log.pattern=%n================================%n%d{yyyy-MM-dd-HH-mm-ss}%n%c%n%m %x%n--------------------------------%n
momomo.log.datepattern='.'yyyy-MM-dd
momomo.log.maxfilesize=5MB
# Root logger option logs all to file
log4j.rootLogger=debug, error, info, console
# global info to console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=${momomo.log.pattern}
log4j.appender.console.Threshold=INFO
# global debug to file
log4j.appender.debug=uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.debug.File=/momomo/Generated/Logs/debug.log
log4j.appender.debug.DatePattern=${momomo.log.datepattern}
log4j.appender.debug.MaxFileSize=${momomo.log.maxfilesize}
log4j.appender.debug.Append=true
log4j.appender.debug.layout=org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern=${momomo.log.pattern}
log4j.appender.debug.Threshold=DEBUG
# global error to file
log4j.appender.error=uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.error.File=/momomo/Generated/Logs/error.log
log4j.appender.error.DatePattern=${momomo.log.datepattern}
log4j.appender.error.MaxFileSize=${momomo.log.maxfilesize}
log4j.appender.error.Append=true
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern=${momomo.log.pattern}
log4j.appender.error.Threshold=ERROR
# This logger just logs for the package momomo.com
log4j.logger.momomo.com=momomo, momomofatal
# momomo debug logger
log4j.appender.momomo=uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.momomo.File=/momomo/Generated/Logs/momomo.log
log4j.appender.momomo.DatePattern=${momomo.log.datepattern}
log4j.appender.momomo.MaxFileSize=${momomo.log.maxfilesize}
log4j.appender.momomo.Append=true
log4j.appender.momomo.layout=org.apache.log4j.PatternLayout
log4j.appender.momomo.layout.ConversionPattern=${momomo.log.pattern}
log4j.appender.momomo.Threshold=DEBUG
# momomo fatal logger
log4j.appender.momomofatal=uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.momomofatal.File=/momomo/Generated/Logs/momomo.fatal.log
log4j.appender.momomofatal.DatePattern=${momomo.log.datepattern}
log4j.appender.momomofatal.MaxFileSize=${momomo.log.maxfilesize}
log4j.appender.momomofatal.Append=true
log4j.appender.momomofatal.layout=org.apache.log4j.PatternLayout
log4j.appender.momomofatal.layout.ConversionPattern=${momomo.log.pattern}
log4j.appender.momomofatal.Threshold=FATAL
Yes, quite many, but there is still many more processes for logging that is declared above.
The server is running really slow now, and that isn't the case when it was just started up. It has gone slower and slower for every hour.
I developed one web applications using struts. Now when i tried to run in another machine I am getting the following error. Following is taken from glassfish server log
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Parsing configuration file [struts-default.xml]
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Unable to locate configuration files of the name struts-plugin.xml, skipping
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Parsing configuration file [struts-plugin.xml]
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Parsing configuration file [struts.xml]
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Loading global messages from ApplicationResources
Also in the browser I am getting java.lang.reflect.InvocationTargetExceptionthis message. Please tell me where the problem lies.
This seems to be a similar problem to what is described in this article:
http://www.java.net/node/705006
It appears to be a GlassFish bug to incorrectly put "SEVERE:" before the log message that actually starts with "INFO".
FYI I came across this with SL4J and Glassfish 3.1. The exact same code logging via the JUL logger works perfectly, and then you get the "SEVERE:" when you swap it out with a proper logger.
Sadly I have not been able to find a resolution, and will post it when I find it. It is equally possible that they re-fix the bug in the next version of GlassFish.
I'd like for log events of type WARN or higher to show the class name. All others would not show the class name. this is both to simplify the log and to not have the performance hit on lower events such as TRACE. This must all go to the same log file.
For example, right now, I have this on my log file:
2010-04-06 18:50:16,416 [main] INFO org.nyjord.lib.gather.TempMachine - initialised successfuly.
2010-04-06 18:50:16,416 [main] FATAL org.nyjord.lib.gather.TempMachine - not all paths could be located
I would prefer this ON THE SAME FILE:
2010-04-06 18:50:16,416 [main] INFO - initialised successfuly.
2010-04-06 18:50:16,416 [main] FATAL org.nyjord.lib.gather.TempMachine - not all paths could be located
Help would be really welcome.
This should be possible, by developing a custom Layout class that does what you want. But I doubt that any of the existing log4j Layout classes would be able to do this.