log4j not printing long log messages - java

While going through the log files I found that long log messages are printed partially in log file.
we are using following ConversionPattern:
%d{ss:SSS} %-5p [%X{moduleName}] [%t] [%X{sessionId}] %c{2} %m%n
log4j version: 1.2.17
I found this issue on production log file, on local machine it works correctly(prints whole log message).
we want to print the whole log message.
is it specific to platform?
can you please help me to resolve this issue?

Related

Log4j not writing logs to file on one Websphere server and writing to file on other

I have maven application with log4j.properties in it with setting to write the logs to a specified file instead of console. When I run the EAR on one of the websphere servers it is creating the file as expected and writing logs to it. But, when I am running the same EAR on other webspehere server it is writing to console instead of writing the logs to the specified file. I have checked the permissions and everything seems to be fine. Please help me in identifying what the issue is. Thanks in advance.
# CONSOLE APPENDER (stdout)
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=DEBUG
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n
# ROLLING FILE APPENDER (on the file system) for memberpolicyattributesservice code
log4j.appender.xxxxService=org.apache.log4j.RollingFileAppender
log4j.appender.xxxxService.Threshold=DEBUG
log4j.appender.xxxxService.File=/var/logs/xxxServer1/xxxServiceLog.log
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout
log4j.appender.xxxxService.layout.ConversionPattern=%d{MM-dd#HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
log4j.appender.xxxxService.MaxFileSize=10000KB
log4j.appender.xxxxService.MaxBackupIndex=30
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout
log4j.appender.xxxxService.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n
# ROLLING FILE APPENDER (on the file system) for hiberate, open source code log files
log4j.appender.open_source_code=org.apache.log4j.RollingFileAppender
log4j.appender.open_source_code.layout=org.apache.log4j.PatternLayout
log4j.appender.open_source_code.Threshold=DEBUG
#message format:YYYY-MM-DD HH:mm:ss,ms [ThreadId] <PRIORITY> classname.message
log4j.appender.open_source_code.layout.ConversionPattern=%d [%t]<%-5p> %c.%m \r\n
#file that will be logged to
log4j.appender.open_source_code.File=/var/logs/xxxServer1/open_source_code.log
log4j.appender.open_source_code.Append=true
log4j.appender.open_source_code.MaxFileSize=1024KB
log4j.appender.open_source_code.MaxBackupIndex=5
#turn on log4j verbose mode
log4j.debug = true
# Set root logger level to INFO and its appender to DSInstrumentor,stdout.
log4j.rootLogger=DEBUG,stdout,xxxxService
# YOUR CATEGORIES (to customize logging per class/pkg/project/etc)
log4j.category.fatal=FATAL,xxxxService
log4j.category.error=ERROR,xxxxService
#This will also enable the logging for all the children (packages and classes) of this package
log4j.logger.com.xxxxx=ALL,xxxxService
# Print only messages of level INFO in the open source code
log4j.logger.org=INFO,open_source_code
You have multiple loggers defined in your root logger (DEBUG, stdout, xxxxService) but the xxxxService loggers look like they're bound to the file system on one of the systems:
log4j.appender.open_source_code.File=/var/logs/xxxServer1/open_source_code.log
Make sure that path is valid for each server in your WAS cluster.
As a side note, you should probably avoid using debug and stdout on a remote server. This is fine for local development in your workstation, but not on a remote box. Instead, provide different log4j properties on your various deployment tiers. This lets you customize the log location or appender (say c:\temp or CONSOLE on your desktop, but /var/logs ... on all remote machines) as well as your log levels (DEBUG for desktop, maybe INFO for QA or Staging, and WARN or ERROR for Production).

Webapp logging settings are being ignored

I'm not able to get output with priority lower than INFO from a webapp. Everything other is being logged correctly.
Log shows the following, yet actual settings put in to the file are seem to be ignored:
INFO: Initializing log4j from
[/var/lib/tomcat-7-main/webapps/myapp/WEB-INF/log4j.properties]
Content of the file is following:
log4j.rootLogger=TRACE, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.conversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.logger.my.webapp=TRACE
log4j.logger.org.springframework.security=TRACE
This configuration works correctly with another machine running openSUSE (while the issue is related to machine running Gentoo). Both of them running Tomcat 7 under Oracle JDK 1.7. Any ideas?

Different logging appender on LOG4J

I'm using log4j 1.2 and I need to:
log everything (including logging from referenced libraries) to console
log from my code to file (and maybe to console)
Using the following code:
log4j.rootLogger=DEBUG, CONSOLE
log4j.com.mypackage=ALL, CONSOLE, CSV
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.err
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %m%n
log4j.appender.CSV=org.apache.log4j.FileAppender
log4j.appender.CSV.File=./myfile.csv
log4j.appender.CSV.Append=false
log4j.appender.CSV.layout=org.apache.log4j.PatternLayout
log4j.appender.CSV.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %m%n
The logfile is not created.
Other try I done:
If I add CSV appender to rootLogger, then the file is created and filled.
If I add CSV appender to rootLogger and disable it, then the file is just created.
If I log only my logger to console... the it works fine
Do you have any idea to solve?
Thanks
You are missing an important part.
The value has to be
log4j.logger.com.mypackage
Note that you are missing logger in the log definition

Shunting certain org.apache.log4j log messages off to a particular log file

We already have extensive logging in our application using org.apache.log4j. We now want to shunt some of these messages off to a new XML log file (while continuing to go to the original log file).
Is this possible? Is there a way we can identify these messages and send them someplace special in addition to the regular log file?
I think you can define two file appenders. One at the root level and other at the package(select the package level as appropriate) level as below:
# Root logger option
log4j.rootLogger=DEBUG, RootFileAppender
#Shunted Logger option
log4j.logger.com.shunted=ERROR,ShuntedFileAppender
# RootFileAppender - used to log messages in the root.log file.
log4j.appender.RootFileAppender=org.apache.log4j.FileAppender
log4j.appender.RootFileAppender.File=root.log
log4j.appender.RootFileAppender.MaxFileSize=100MB
log4j.appender.RootFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RootFileAppender.layout.ConversionPattern= %5p [%t] (%F:%L) - %m%n
# ShuntedFileAppender - used to log messages in the shunted.log file.
log4j.appender.ShuntedFileAppender=org.apache.log4j.FileAppender
log4j.appender.ShuntedFileAppender.File=shunted.log
log4j.appender.ShuntedFileAppender.MaxFileSize=10MB
log4j.appender.ShuntedFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ShuntedFileAppender.layout.ConversionPattern= %5p [%t] (%F:%L) - %m%n
Please Note: You can define the two logger option as different levels as well. In above example, ROOT is defined at DEBUG while shunted is devined as ERROR level.

Web Service and Log4J Output to File

So, I have the log4j configurations set up and it output to the console just fine. But I need it to output to a file now. I am using Axis2 in Eclipse Galileo.
I edited the default log4j.properties file to this:
Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
log4j.rootCategory=INFO, CONSOLE, LOGFILE
Set the enterprise logger priority to FATAL
log4j.logger.org.apache.axis2.enterprise=FATAL
log4j.logger.de.hunsicker.jalopy.io=FATAL
log4j.logger.httpclient.wire.header=FATAL
log4j.logger.org.apache.commons.httpclient=FATAL
CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %m%n
LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=C:\Users\*username*\Desktop\Android\Android_WS\src\wtp\AndroidWS_Log.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
But the output is still not getting to the Log file. Any help would be much appreciated. Thanks Guys!
Remove line 2:
log4j.rootCategory=INFO, CONSOLE
Also, try using a forward slash, '/' for the directory separator:
log4j.appender.LOGFILE.File=C:/Users/*username*/Desktop/Android/Android_WS/src/wtp/AndroidWS_Log.log
Make sure that your server has write access rights to the log file.

Categories