I am using Eclipse to create (Session Bean + MDB), deployed in OpenEJB. It works. Now how can I output the log debug info to console ? I need to add a log4j.properties in the project or to change the OpenEJB server properties ?
Thanks.
You need to add log4j.properties to your classpath and add the following configuration to log the OPENEJB debug to the console.
log4j.category.OpenEJB = warn
log4j.category.OpenEJB.server = info
log4j.category.OpenEJB.startup = info
log4j.category.OpenEJB.startup.service = warn
log4j.category.OpenEJB.startup.config = info
log4j.category.OpenEJB.hsql = info
log4j.category.CORBA-Adapter = info
log4j.category.Transaction = warn
log4j.category.org.apache.activemq = error
log4j.category.org.apache.geronimo = error
log4j.category.openjpa = error
You can modify the logging by changing the Log Levels.
Related
An webapp deployed in Weblogic is using SLF4J with Log4j for logging, but all the logging ends up in the STDERR, without any possible reason.
Checked the start-up parameter on the Weblogic server: -Dweblogic.Stderr=/opt/logs/exp.err
Checked if the "Redirect stderr logging enabled" is not true and the other logging settings in the Weblogic console, is not true
Checked and removed all the forgotten log4j.properties in the source code.
Searched for System.setErr() in the code, which could redirect the Log4J output to STDERR, not found anything
Adapted the versions of Log4J (1.2.13 and 1.2.16) and SLF4J (1.6.4 and 1.7.7) without any change
Added jcl-over-slf4j and jul-to-slf4j to Maven dependencies
Set Log4J and SLF4J as "provided", since these are a part of the general server libs to avoid conflicts
Complete refactoring to SLF4J - removed all occurrences of Log4j (Logger class) from the includes in all Java classes
This is the log4j configuration:
log4j.rootCategory = WARN,fileA
log4j.appender.fileA = org.apache.log4j.RollingFileAppender
log4j.appender.fileA.file = /opt/logs/exp_application_log4j.log
log4j.appender.fileA.layout = org.apache.log4j.PatternLayout
log4j.appender.fileA.Threshold = WARN
log4j.appender.fileA.layout.ConversionPattern = %t %d %-5p | (%c:%L) - %m%n
log4j.appender.fileA.MaxFileSize = 10MB
log4j.appender.fileA.MaxBackupIndex = 5
log4j.category.com.pams = WARN
log4j.category.de = WARN
log4j.category.com = WARN
log4j.category.com.gti.cache = WARN
log4j.category.com.cs.pu = ERROR
log4j.category.com.cs.common = FATAL
log4j.category.com.cs = WARN
log4j.category.com.ino.dp = WARN
log4j.category.org.apache.fop = ERROR
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
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" );
I use log4j2 as my default logging, when I run my webapp with Wildfly, My logs get wrapped as an INFO like follows:
17:28:31,127 INFO [stdout] (default task-6) DEBUG 2015-10-15 17:28:31,127 za.co.manticore.core.aspect.cacing.CachingAspect - Entering Caching Aspect for method getApplicationMeta
This is causing my logs to be cluttered, as all my logs are logged as INFO. How can I configure Wildfly to not do this. I have done some googleing but could not find an answer that worked.
I think, you should properly configure log4j2. It looks like currently it has console appender - try remove console appender from log4j2 config
Ok you can configure Wildfly not to wrap your stdout and stderr logs.
Run the following CLI commands
sh jboss-cli.sh --connect '/subsystem=logging/console-handler=JUST-PRINT:add(formatter="%s%E%n")'
sh jboss-cli.sh --connect '/subsystem=logging/logger=stderr:add(use-parent-handlers="false", handlers=[JUST-PRINT])'
sh jboss-cli.sh --connect '/subsystem=logging/logger=stdout:add(use-parent-handlers="false", handlers=[JUST-PRINT])'
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