SL4J timestamps - java

I just switched my project from JUL (java.util.logging) to SL4J over JUL. Everything works great, I only have one grievance: when logging, the timestamps are not very relevant to me, for example:
2 [pool-2-thread-1] INFO com.lexit.server.ServerContext - Context initialized.
703 [pool-2-thread-1] INFO com.lexit.server.ServerContext - Connection with database succesful.
1144 [pool-2-thread-1] INFO com.lexit.server.ServerContext - External emails will be sent
1144 [pool-2-thread-1] INFO com.lexit.server.ServerContext - Alarms will be sent fr
1146 [pool-2-thread-1] INFO java.lang.Class - Adding reccuring timer with id: 1234567
How can I configure SL4J to have more relevant timestamps (e.g. 8-Mar-2012 5:38:00 PM)??

That's the logging format emitted by SLF4J's SimpleLogger.
See for yourself at:
http://www.slf4j.org/apidocs/org/slf4j/impl/SimpleLogger.html
SimpleLogger is the logger that gets used when you haven't added one of the SLF4J "bridge" jars to your classpath. Make sure you add slf4j-jdk14-x.x.x.jar (the JUL bridge) to your classpath, so that SLF4J will be configured to bridge to JUL.

Related

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

Disable false-positive C3P0 logs

My Java7 project uses c3p0 (0.9.5.1) for connection pooling and Log4j (1.2.17) for logging. It seems that log4j logs c3p0 INFO logs in ERROR level:
2017-02-09T21:30:19.545+01:00 app_r41 jsvclog[5135] err: JSVC [MLog-Init-Reporter] INFO com.mchange.v2.log.MLog - MLog clients using slf4j logging.
2017-02-09T21:30:19.959+01:00 app_r41 jsvclog[5135] err: JSVC [main] INFO com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.5.1 [built 16-June-2015 00:06:36 -0700; debug? true; trace: 10]
2017-02-09T21:30:21.294+01:00 app_r41 jsvclog[5135] err: JSVC [main] INFO com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource - [configuration of ComboPooledDataSource follows here...]
Now this is confusing and I want to disable it.
This is the relevant part of my log4j.properties configuration:
log4j.rootLogger=INFO, SYSLOG_APPENDER
log4j.logger.com.mchange=WARN, SYSLOG_APPENDER
What am I missing?
Setting this system property during service start-up fixes the problem:
System.setProperty( "com.mchange.v2.log.Log4jMLog.DEFAULT_CUTOFF_LEVEL", "WARNING" );

Spring app not deploying in debug mode

I've some kind of weird and frustrating bug wich block debug mode. It started suddenly and i can't get rid of it even trying to revert last changes.
When running my webApp in normal mode, it deploy and run properly, but when running it in debug mode, it can't finish, my last stacktrace info sais:
[...] INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/mvc/i18n.xml]
DEBUG: org.springframework.web.context.support.XmlWebApplicationContext - Bean factory for WebApplicationContext for namespace 'appServlet-servlet': org.springframework.beans.factory.support.DefaultListableBeanFactory#2222af8c: defining beans [gruposTrabajoServiceImpl,usuarioServiceImpl,vacacionesServiceImpl,calendarioServiceImpl,administracionServiceImpl,empleadosServiceImpl,aeropuertosServiceImpl,rotacionesServiceImpl,rotacionesController,empleadosController,vacacionesController,aeropuertosController,loginController,includeController,administracionController,gruposTrabajoController,informesController,festivoDAOImpl,empleadoDAOImpl,limitacionDAOImpl,habilidadEmpDAOImpl,fpCalendarioEmpDAOImpl,autorizacionDAOImpl,minimosPatronDAOImpl,ceAnoEmpDAOImpl,poaUpaDAOImpl,turnoRotacionDAOImpl,patronRotacionDAOImpl,anoEmpDAOImpl,grupoTrabajoDAOImpl,incidenciaDiaDAOImpl,telefonoEmpDAOImpl,usuarioDAOImpl,escalaDAOImpl,limitacionEmpDAOImpl,visibleCntMinimosDAOImpl,configuracionContratoEscalaDAOImpl,puntuacionDAOImpl,vpCalendarioEmpDAOImpl,usuarioEscalaDAOImpl,anoEscalaDAOImpl,vpCupoGtDAOImpl,habilidadDAOImpl,formacionEmpDAOImpl,dominioDAOImpl,formacionDAOImpl,tipoTurnoDAOImpl,incidenciaDAOImpl,observacionDiaDAOImpl,rotacionDAOImpl,turnoDAOImpl,calendario,mes,perfilAspect,excelEscala,excelAnual_,excelEscala_,globalConstants,dominioConstants,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#1,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#1,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#2,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#2,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#3,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#3,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.web.servlet.handler.SimpleMappingExceptionResolver#0,messageSource,localeResolver,org.springframework.web.servlet.handler.MappedInterceptor#1]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#4349e631
DEBUG: org.springframework.web.context.support.XmlWebApplicationContext - Using MessageSource [org.springframework.context.support.ResourceBundleMessageSource: basenames=[messages]]
DEBUG: org.springframework.web.context.support.XmlWebApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster#6e3f6d73]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#2222af8c: defining beans [gruposTrabajoServiceImpl,usuarioServiceImpl,vacacionesServiceImpl,calendarioServiceImpl,administracionServiceImpl,empleadosServiceImpl,aeropuertosServiceImpl,rotacionesServiceImpl,rotacionesController,empleadosController,vacacionesController,aeropuertosController,loginController,includeController,administracionController,gruposTrabajoController,informesController,festivoDAOImpl,empleadoDAOImpl,limitacionDAOImpl,habilidadEmpDAOImpl,fpCalendarioEmpDAOImpl,autorizacionDAOImpl,minimosPatronDAOImpl,ceAnoEmpDAOImpl,poaUpaDAOImpl,turnoRotacionDAOImpl,patronRotacionDAOImpl,anoEmpDAOImpl,grupoTrabajoDAOImpl,incidenciaDiaDAOImpl,telefonoEmpDAOImpl,usuarioDAOImpl,escalaDAOImpl,limitacionEmpDAOImpl,visibleCntMinimosDAOImpl,configuracionContratoEscalaDAOImpl,puntuacionDAOImpl,vpCalendarioEmpDAOImpl,usuarioEscalaDAOImpl,anoEscalaDAOImpl,vpCupoGtDAOImpl,habilidadDAOImpl,formacionEmpDAOImpl,dominioDAOImpl,formacionDAOImpl,tipoTurnoDAOImpl,incidenciaDAOImpl,observacionDiaDAOImpl,rotacionDAOImpl,turnoDAOImpl,calendario,mes,perfilAspect,excelEscala,excelAnual_,excelEscala_,globalConstants,dominioConstants,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#1,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#1,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#2,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#2,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#3,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#3,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.web.servlet.handler.SimpleMappingExceptionResolver#0,messageSource,localeResolver,org.springframework.web.servlet.handler.MappedInterceptor#1,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#4349e631
It always stays in the same place Pre-instantiating singletons in...
I've tried running my app in both Tomcat 7 and weblogic 10.3.4 but i get the same result.
Any idea? I'm lost without debug mode.
Thank you very much for your help
A long shot, but maybe you added some breakpoints to the code of one of your classes, and when in debug mode, the execution waits for you to explicitly signal it to continue?
You probably have some debug window open. What does it show there?
Just encountered the exact same issue with STS IDE version 3.6.4 and it seems that it was stopped at a breakpoint without highlighting it. Thus I was unawered of the situation. I cleared all of the breakpoints and it magically works now.

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 disable Hibernate log messages

I'm using Hibernate for a personal project.
In my project, I have these directory:
+ conf
log4j.properties
+ bin
my classes
Using Windows console, I go to project directory (the parent of bin and conf) and I start the application with a command like this:
java -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main
My log4j.properties file is this (taken from an hibernate example):
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d - %m%n
log4j.rootLogger=info, stdout
log4j.logger.org.hibernate=error
log4j.logger.org.hibernate.tool.hbm2ddl=error
log4j.logger.org.hibernate.hql.ast.QueryTranslatorImpl=error
log4j.logger.org.hibernate.hql.ast.HqlSqlWalker=error
log4j.logger.org.hibernate.hql.ast.SqlGenerator=error
log4j.logger.org.hibernate.hql.ast.AST=error
On application start, this is the output:
2010-11-06 19:00:56,376 - Logger.getRootLogger().info() statement
12 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.3-Final
13 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
16 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
20 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
108 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: com/moc/hibernate.cfg.xml
108 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: com/moc/hibernate.cfg.xml
124 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from file: conf\hiber\Customer.hbm.xml
.
.
.
and so on
.
.
.
795 [main] INFO org.hibernate.impl.SessionFactoryImpl - closing
795 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:mysql://localhost/mydb
The color of Hibernate log lines is red, my log lines are black.
Why I still see INFO output from Hibernate? What am I doing wrong?
A good way of checking your log4j configuration and the events occuring at runtime is adding
-Dlog4j.debug option to the java command line. In your case it will become:
java -Dlog4j.debug -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main
This will throw information on console of the sequence of loading of log4j configuration. You can then determine if your log4j.properties is getting loaded correctly or not.
Your log4j configuration looks ok, is your log4j.properties file on the classpath and in the root package? I.e. is it in the root of conf, lib1.jar, lib2.jar pr any other jar/directory in your classpath?
Try this to check if the file is being loaded correctly.
On this line:
log4j.rootLogger=info, stdout
chage to
log4j.rootLogger=error, stdout
This will set the log level for the root logger and hence all loggers to ERROR, if you are still seeing the INFO log entries then your log4j.properties file must not be loading correctly, most likely for the reasons stated above.
Can you try this syntax instead?
log4j.category.org.hibernate=ERROR

Categories