-1

Theis is my log4j.properties file:

log4j.rootCategory=INFO, R

log4j.logger.com.smsoffice=DEBUG

#log4j.logger.org.apache.wicket=DEBUG

#log4j.logger.org.hibernate=DEBUG
#log4j.additivity.org.hibernate.SQL=false

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.home}/webapps/ROOT/logs/smsoffice.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=20
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss,SSS} %p %C.%M:%L - %m%n   

This file is in src/main/resources. I am using tomcat web server. In com.smsoffice.launch I have WebApp.java and I am using log4j in this way:

private static final Logger logger = Logger.getLogger(WebApp.class);
logger.info("Initializing web application");

When I start the app log4j writes in the console only this:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext). log4j:WARN Please initialize the log4j system properly.

I have logs in ${catalina.home}/webapps/ROOT/logs/smsoffice.log but it is not shown in the console when I am debuging.

Anyone knows what I am missing ?

EDIT:

here is the full log:

log4j: Trying to find [C:\projects\smsofficenew\app\sms-office-webapp\src\main\resources\log4j.properties] using context classloader WebappClassLoader
  context: /ROOT
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1489c411
.
log4j: Trying to find [C:\projects\smsofficenew\app\sms-office-webapp\src\main\resources\log4j.properties] using WebappClassLoader
  context: /ROOT
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@1489c411
 class loader.
log4j: Trying to find [C:\projects\smsofficenew\app\sms-office-webapp\src\main\resources\log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [C:\projects\smsofficenew\app\sms-office-webapp\src\main\resources\log4j.properties].
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

BUT the resource [C:\projects\smsofficenew\app\sms-office-webapp\src\main\resources\log4j.properties] is here !!! So the real problem is why log4j cannot find this file ???

johnpolqkov
  • 93
  • 2
  • 13

2 Answers2

0

you may want to add following log4j.properties file in resources 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
log4j.appender.file=org.apache.log4j.RollingFileAppender
#outputs to Tomcat home
log4j.appender.file.File=${catalina.home}/logs/myapp.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

try changing file location though

Hope this helps

  • no result .. this is the error : log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository. log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext). log4j:WARN Please initialize the log4j system properly. – johnpolqkov Jul 13 '15 at 09:03
0

In your log4j.properties file you have not defined what exactly you want to append i.e. log4j.appender.stdout.Target=System.out.

You can just look for any standard file and you will get it.

Where exactly you are placing your properties file?

Kulbhushan Singh
  • 627
  • 4
  • 20