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
Related
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
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
I have a snippset that I use like gazillion times in Linux that absolutely have no problem. But on windows it fails.
log4j: Using URL [file:/C:/Users/vbb/Documents/NetBeansProjects/MailNotification/./log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL file:/C:/Users/vbb/Documents/NetBeansProjects/MailNotification/./log4j.properties
log4j: Could not find root logger information. Is this OK?
log4j: Finished configuring.
log4j:WARN No appenders could be found for logger (com.mycompany.mailnotification.Main).
log4j:WARN Please initialize the log4j system properly.
The code like this:
System.setProperty("log4j.configuration", new File(".", File.separatorChar + "log4j.properties").toURL().toString());
final Logger logger = Logger.getLogger(Main.class);
logger.debug("Program start!");
Here is the properties file which is placed everywhere from src\main\resources, src\test\resources... In linux, I just place it in project folder.
# 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.RollingFileAppender
log4j.appender.file.File=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
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
I don't understand why my Log4J is not logging to file. Ive been looking many similar posts but none helped me. I configured all correctly, but it doesn't log to the file.
Let me show you, this is the config log4J.properties:
# 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=log.out
log4j.appender.file.ImmediateFlush=true
log4j.appender.file.MaxFileSize=1024MB
log4j.appender.file.MaxBackupIndex=1
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.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
And this is how I use the Logger:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
private Logger logger = LoggerFactory.getLogger(GameBoardService.class);
...
logger.info("log this text into file....");
Try to specify your base package for the logging
log4j.logger.[your own class base package ]=INFO
e.g.
log4j.logger.org.springframework=WARN
log4j.logger.org.hibernate=WARN
Be specific with the log path to enable you to easily locate the path, e.g. below.
log4j.appender.file.File=/var/logs/log.out
Furthermore, /var/logs/log.out is created in Windows as C:\var\logs\log.out and in Linux as /var/logs/log.out and there is no need to switch path slashes according to OS. Just a reminder, ensure you have permission to the specified path.