2

I have my log4j.properties file as below:

log4j.rootLogger=WARN, DebugAppender

#Debug logging
log4j.appender.DebugAppender=org.apache.log4j.RollingFileAppender
log4j.appender.DebugAppender.Threshold=WARN
log4j.appender.DebugAppender.File=activityLog.log
log4j.appender.DebugAppender.MaxFileSize=200KB
log4j.appender.DebugAppender.MaxBackupIndex=5
log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.DebugAppender.layout.ConversionPattern=%d{DATE} %t - %m%n

The file is added in the classpath and in src/resources folder.... my project is a maven project and I am using springshell technology so that my application runs on a command prompt... everything works perfect but when I execute a particular command in my application it gives me below warning:

 log4j:WARN No appenders could be found for logger (com.gedas.rvs.data.net.ClientAuthenticationType).
 log4j:WARN Please initialize the log4j system properly.
 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Can you please help me about what am I doing wrong?

Eduardo Yáñez Parareda
  • 9,126
  • 4
  • 37
  • 50
shardul
  • 61
  • 6

2 Answers2

1

You are definning an appender (you are explaining log4j where and how to write the messages to) but you do not define which categories (the "name" given to the loggers in your program) should use it.

This tells log4j that all of the categories (rootLogger) should use DebugAppender to write messages of severity DEBUG or higher

# Root logger option
log4j.rootLogger=DEBUG, DebugAppender

Alternatively, if you have a logger called example.org.MyClass, you could add

log4j.example.org.MyClass=INFO, DebugAppender

or

log4j.example.org=INFO, DebugAppender

to send INFO and above messages to the appender.

SJuan76
  • 24,532
  • 6
  • 47
  • 87
  • Actually in my application various commands are used ...the application works alright for all the commands except one.... when i execute this particular command it gives the above warning msg onto the command prompt.....so its bit strange to analyze for me why only a typical command's execution would reproduce this msg....although the command gets successfully executed after giving this msg – shardul Sep 01 '15 at 08:49
  • Because that command is the only that tries to write to a log4j logger (even from your code or from some 3rd party API you are using). – SJuan76 Sep 01 '15 at 09:11
  • ok it might be 3rd party API , but the interesting thing here is , i get the msg only first time when i execute the command. If i execute the command immediately after , the warning msg will not come. – shardul Sep 01 '15 at 12:42
  • any idea why this must be only for the first time? – shardul Sep 02 '15 at 05:36
  • It is normal that it only appears once per execution; if you have changed your file as it is in the OP now it may be a problem with the location of the file. Check where the file appears inside your compiled files (default location is the root package; you can specify another location using the log4j.configuration system property (http://stackoverflow.com/a/5081363/598289) – SJuan76 Sep 02 '15 at 07:21
  • it does appears in the root package...i have tried to change the location but avail to no success..... but dont you think its strange that the msg appears only once and not the next time when the same command is executed – shardul Sep 02 '15 at 07:47
0

It seems it requires file appender. check the log properties files again. Here is my log properties file, have a look.

# Root logger option
log4j.rootLogger=DEBUG, 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=C:\\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

log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.type=trace

Instead of only debug appender, add other lines too and try. It might work!!

monksy
  • 14,156
  • 17
  • 75
  • 124