Log4j doesnot log the info in server - java

I have implemented the log4j with following properties.
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to consol
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/home/../log4j-application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
It is working on localhost where in server side it log nothing . I guess above are the general configuration. Is there something i am missing here? I use TomEE on both client and server.Also i used the logger as following. It also does not write in local file. Only logger seems to work on client.
private static final Logger LOGGER = Logger.getLogger(MyClass.class);

I think problem with this line
log4j.appender.file.File=/home/../log4j-application.log
Please use (if you have a log folder)
log4j.appender.file.File=log/log4j-application.log

Related

My log file deleted after reboot with probe

I am using probe along with tomcat. My application which is deployed in tomcat 8.5 use log4j for its logging.
This is Log4j.properties configuration :
# Root logger option
log4j.rootLogger=DEBUG, file
log4j.logger.org.hibernate.SQL = DEBUG, file
log4j.logger.org.hibernate.type = TRACE, file
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${catalina.base}/logs/my-app.log
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.rollingPolicy.ActiveFileName=${catalina.base}/logs/my-app.log
log4j.appender.file.rollingPolicy.FileNamePattern=${catalina.base}/logs/archive/my-app-%d{yyyy-MM-dd}.log.gz
Everything is fine and i could fine my logs, but when the server restart i lost everything.
It seams like probe delete the log file after reboot
Am i missing something in the configuration on my application or even in the prob side?
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
#outputs to Tomcat home
log4j.appender.file.File=${catalina.home}/logs/my-app.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
can you check above code?
put all properties in your log4j properties file

can't able to implement log4j for JBOSS EAP 7 using java?

i have an application, i have applied log4j, but i can't able to create log file inside jboss application.
when i put absolute path of system in log4j.appender.file.File= D:/log/application.log it was working fine but when i put log4j.appender.file.File= ${jboss.server.home.dir}/log/application.log it is not working.
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File= ${jboss.server.home.dir}/log/application.log
log4j.appender.file.MaxFileSize=5KB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
try using $JBOSS_HOME instead of ${jboss.server.home.dir}.. so it becomes
log4j.appender.file.File= ${JBOSS_HOME }/log/application.log

Log4j not send logs to linux SYSLOG

I want implement log4j to my java project. I put the jar in lib folder and configure log4j.properties file. Logs successfuly shows in console, but I can't see that logs in SYSLOG app (KSYSLOG) of my kubuntu. this is my properties file:
log4j.rootLogger=INFO, stdout, SYSLOG, file
# Redirect log messages to console
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a SYSLOG
log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG.syslogHost=127.0.0.1
log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.SYSLOG.layout.conversionPattern=%d{ISO8601} %-5p [%t] %c{2} %x - %m%n
log4j.appender.SYSLOG.Facility=LOCAL1
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/var/log/ log4j-application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
what is incorrect in this properties file or what I do incorrect?
I found the solutin in this thread Writing log data to syslog using log4j
we must add
$ModLoad imudp
$UDPServerRun 514
to rsyslog.conf and restart rsyslog

How to initialize the log4j system properly

I'm getting two warnings.
log4j:WARN No appenders could be found for logger (com.org.Resolver).
log4j:WARN Please initialize the log4j system properly.
How to resolve it?
My java class name Resolver.java
In java class i'm calling
private static Log log = LogFactory.getLog(Resolver.class);
You need to put log4j.properties or log4j.xml in your classpath. So, create file name log4j.properties and replace the content with below:
# Root logger option
log4j.rootLogger=INFO, DEBUG, stdout, file
# Redirect log messages to console
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
#. represents the current folder (usually the project root folder)
log4j.appender.file.File=./logging.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

log4j doesn't write to file in a Tomcat7 web application on Amazon server

I used log4j for logging in my web application which is deployed using Tomcat on Amazon Cloud.
I can see the output of log4j on catalena. But, log file is not being created in the given location "/home/ec2-user/EmailLog/userdetails.log" and no logging is being done.
The same web application is running fine and creating the file and logging when tried on localhost.
My log4j.properties content:
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/home/ec2-user/EmailLog/userdetails.log
log4j.appender.file.MaxFileSize=15MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c:%L - %m%n
# Direct log messages to stdout
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{yyyy-MM-dd HH:mm:ss} %-5p %c:%L - %m%n
And I instantiated the Logger by:
private static final Logger logger = Logger.getLogger(DBManager.class);
Please, suggest modification to make it work on Tomcat-Amazon.

Categories

Resources