5

This is my 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=${catalina.home}\MyLog\PmcDemo.log
log4j.appender.file.MaxFileSize=1MB
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{1}:%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{1}:%L - %m%n

I am using tomcat 6.0, in my application I have used Logger from log4j yet I don't see any output on server console or in the log file. My application is using struts2 as front end, Spring framework as middle layer and hibernate as the end layer. I don't see my application logging how can I enable it in tomcat 6?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Bilbo Baggins
  • 2,899
  • 10
  • 52
  • 77

2 Answers2

7

You need to switch the backslashes for forward slashes:

${catalina.home}/MyLog/PmcDemo.log

or to escape them

${catalina.home}\\MyLog\\PmcDemo.log

If that doesn't help, let us know the structure of your project and where the log4j.properties file is stored.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
cowls
  • 24,013
  • 8
  • 48
  • 78
  • Ok my fault I should have posted my environment too, I am using Windows 7. – Bilbo Baggins Nov 29 '13 at 08:47
  • Ok I suggest you try changing to / anyway. I am also using windows and using single '\' broke my logging – cowls Nov 29 '13 at 09:04
  • also see https://stackoverflow.com/questions/11268120/log4j-does-not-log-anything for other suggestions for possible remedies for things like this... – hello_earth Nov 26 '19 at 08:20
1

Try this steps,

If running Tomcat 6.x:

 1. If you have not already done so, modify the <<TOMCAT_HOME>>/conf/catalina.properties file so that the shared classloader mechanism work the same as Tomcat 5.x.
 2. To do this, verify that the entry beginning with shared.loader= reads shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar If running Tomcat 5.x or higher:

If running Tomcat 5.x or higher:

 3. If it does not already exist, create a "shared/classes" directory under <<TOMCAT_HOME>>.

 4. If it does not already exist, create a "shared/lib" directory under <<TOMCAT_HOME>>.
 5. Copy log4j-###.jar into <<TOMCAT_HOME>>/shared/lib.

    **Note:** Any specific version of log4j-###.jar should work. You can download the stable log4j version 1.2 installation from http://logging.apache.org/log4j/1.2/download.html

 6. Copy a log4j.properties file into <<TOMCAT>>/shared/classes.

Example
To get a log file named "initiate.log" to show up in the <<TOMCAT_HOME>>/logs directory, an initial version of log4j.properties file is:

    log4j.rootLogger=ERROR, R

    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

    # Pattern to output the caller's file name and line number.
    log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

    log4j.appender.R=org.apache.log4j.RollingFileAppender
    log4j.appender.R.File=${catalina.home}/logs/initiate.log

    log4j.appender.R.MaxFileSize=1000KB
    log4j.appender.R.MaxBackupIndex=5

    log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern=%d{ABSOLUTE} 5-5p %c{2} - %m %n

    log4j.logger.org.springframework=ERROR
    log4j.logger.org.springframework.web.servlet.mvc=ERROR

    #set to DEBUG to see hibernate and connection-pool logging output
    log4j.logger.org.hibernate=ERROR
    log4j.logger.org.apache.commons.dbcp=ERROR

    #set to DEBUG to see Initiate-specific logging output
    log4j.logger.com.initiatesystems=DEBUG

    #set to DEBUG to set Initiate-specific verbose logging output
    log4j.logger.verbose=ERROR

Quoted from: http://pic.dhe.ibm.com/infocenter/initiate/v9r5/index.jsp?topic=%2Fcom.ibm.datatrust.doc%2Ftopics%2Ft_datatrust_configuring_log4j_logging_apachetomcat.html

cowls
  • 24,013
  • 8
  • 48
  • 78
Vipul Paralikar
  • 1,508
  • 10
  • 22
  • This is not a fix but a workaround. It is usually preferable to use separate log4j.properties per application then one global one. – cowls Nov 29 '13 at 09:56