Different log4j patterns on the same same file depending on log level? - java

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.

Related

Spring Logging setting Log level for JDK classes

currently I'm trying to set trace logging level for internal JDK classes, especially for the new HttpClient.
When I add to my application.yaml:
logging:
level:
root: INFO
Everything logs in trace.
But when I want to enable trace logging only for JDK packages like:
logging:
level:
root: INFO
jdk.internal.net.http: TRACE
Those packages don't start log in trace, the entire app uses root level, which is INFO.
What do I need to solve this problem? Thanks guys.

Jetty Runner IDEA Community Logging

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

log4j error message in repast simphony - batch run

when starting my Repast Simphony Model in Batch run I get this error message:
log4j:WARN No appenders could be found for logger (RLFA.society3.run.1.1).
log4j:WARN Please initialize the log4j system properly.
The answer here concerning log4j http://repast.sourceforge.net/docs/tutorial/SIM/Frequently%20Asked%20Questions.html#FrequentlyAskedQuestions-log4j doesn't help at all, since I got the problem ONLY when starting batch run. When starting the model normally everything is fine. And I also couldn't adapt any of the other log4j problems/answers here in stackoverflow, since that problem within Repast Simphony seems rather specific.
Anyone ran into this problem before and solved it? Or Maybe an idea, what this RLFA is?
Note: the error occurs when the model is fully initialized, during the first step.
Thanks for every help,
Andy
edit: in velocity.log I found this loggings, where it says that a VM_global_library.vm is missing - but does this help further?
2011-10-24 18:11:32,505 - SimpleLog4JLogSystem initialized using logfile 'velocity.log'
2011-10-24 18:11:32,506 - **************************************************************
2011-10-24 18:11:32,507 - Starting Jakarta Velocity v1.4
2011-10-24 18:11:32,507 - RuntimeInstance initializing.
2011-10-24 18:11:32,507 - Default Properties File: org\apache\velocity\runtime\defaults\velocity.properties
2011-10-24 18:11:32,507 - Trying to use logger class org.apache.velocity.runtime.log.SimpleLog4JLogSystem
2011-10-24 18:11:32,507 - Using logger class org.apache.velocity.runtime.log.SimpleLog4JLogSystem
2011-10-24 18:11:32,601 - Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
2011-10-24 18:11:32,616 - Resource Loader Instantiated: org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
2011-10-24 18:11:32,616 - ClasspathResourceLoader : initialization starting.
2011-10-24 18:11:32,616 - ClasspathResourceLoader : initialization complete.
2011-10-24 18:11:32,662 - ResourceCache : initialized. (class org.apache.velocity.runtime.resource.ResourceCacheImpl)
2011-10-24 18:11:32,662 - Default ResourceManager initialization complete.
2011-10-24 18:11:32,672 - Loaded System Directive: org.apache.velocity.runtime.directive.Literal
2011-10-24 18:11:32,681 - Loaded System Directive: org.apache.velocity.runtime.directive.Macro
2011-10-24 18:11:32,732 - Loaded System Directive: org.apache.velocity.runtime.directive.Parse
2011-10-24 18:11:32,743 - Loaded System Directive: org.apache.velocity.runtime.directive.Include
2011-10-24 18:11:32,754 - Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
2011-10-24 18:11:33,001 - Created: 20 parsers.
2011-10-24 18:11:33,131 - Velocimacro : initialization starting.
2011-10-24 18:11:33,132 - Velocimacro : adding VMs from VM library template : VM_global_library.vm
2011-10-24 18:11:33,182 - ResourceManager : unable to find resource 'VM_global_library.vm' in any resource loader.
2011-10-24 18:11:33,182 - Velocimacro : error using VM library template VM_global_library.vm : org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'VM_global_library.vm'
2011-10-24 18:11:33,182 - Velocimacro : VM library template macro registration complete.
2011-10-24 18:11:33,182 - Velocimacro : allowInline = true : VMs can be defined inline in templates
2011-10-24 18:11:33,182 - Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
2011-10-24 18:11:33,182 - Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.
2011-10-24 18:11:33,183 - Velocimacro : messages on : VM system will output logging messages
2011-10-24 18:11:33,183 - Velocimacro : autoload off : VM system will not automatically reload global library macros
2011-10-24 18:11:33,183 - Velocimacro : initialization complete.
2011-10-24 18:11:33,183 - Velocity successfully started.
The problem was that I forgot to define an Outputter in Repast Simphony.
From Repast FAQ:
https://repast.github.io/docs/RepastSimphonyFAQ.pdf
3.4 log4j:WARN No appenders could be found for logger (MessageCen- ter. INTERNAL.repast.simphony.ui.RSUIPlugin)
Several people have reported errors when trying to start a Repast
Simphony model such as log4j:WARN No appenders could be found for
logger (MessageCenter. INTERNAL.repast.simphony.ui.RSApplication ).
log4j:WARN Please initialize the log4j system properly. with some
variability in the (MessageCenter....) part.
In almost all cases, this warning is NOT actually related to logging
configuration errors, and more likely it is related to problems in the
model.score file like incorrect paths, or missing agent class files.
When you start a Repast model and you get the log4j message in the
Eclipse console, you can usually found more information from the
Repast runtime error log. The error log is available when the icon in
the lower right corner of the Repast runtime is flashing.
I tried to run a RepastSymphony model from the command line and also had an error message about log4j appenders. For me the solution was to include the project directory, where my MessageCenter.log4j.properties file is located, in the class path, e.g
-cp ='.;./bin/.;./lib/*;
instead of only
-cp ='./bin/.;./lib/*;

Unable to run struts program

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.

What does rootCategory in log4j.properties mean?

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

Categories