views:

1266

answers:

3

I'm running some java processes on Windows 2003 server R2 I'm using Apache log4j-1.2.8. All my processes called via one jar file with different parameter example

    java -jar process.jar one 
    java -jar process.jar two
    java -jar process.jar three

And I config log4j.properties follow

#=============================== 
# Declare Variables
#===============================
logpath=${user.dir}/log/
simple_pattern=%d{yyyy-MM-dd HH:mm:ss.SSS}%-5x - %m%n
backup_pattern='.'yyyy-MM-dd

#===============================
# PROCESS & STANDARD OUTPUT
#===============================
log4j.logger.process.Process=NULL,proclog,procstdout
log4j.appender.proclog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.proclog.File=${logpath}process.log
log4j.appender.proclog.DatePattern=${backup_pattern}
log4j.appender.proclog.layout=org.apache.log4j.PatternLayout
log4j.appender.proclog.layout.conversionPattern=${simple_pattern}

log4j.appender.procstdout=org.apache.log4j.ConsoleAppender
log4j.appender.procstdout.layout=org.apache.log4j.PatternLayout
log4j.appender.procstdout.layout.ConversionPattern=${simple_pattern}

#===============================
# ONE
#===============================
log4j.logger.process.log.One=NULL,one
log4j.appender.one=org.apache.log4j.DailyRollingFileAppender
log4j.appender.one.File=${logpath}one.log
log4j.appender.one.DatePattern=${backup_pattern}
log4j.appender.one.layout=org.apache.log4j.PatternLayout
log4j.appender.one.layout.conversionPattern=${simple_pattern}

#===============================
# TWO
#===============================
log4j.logger.process.log.Two=NULL,two
log4j.appender.two=org.apache.log4j.DailyRollingFileAppender
log4j.appender.two.File=${logpath}two.log
log4j.appender.two.DatePattern=${backup_pattern}
log4j.appender.two.layout=org.apache.log4j.PatternLayout
log4j.appender.two.layout.conversionPattern=${simple_pattern}

#===============================
# THREE
#===============================
log4j.logger.process.log.Three=NULL,three
log4j.appender.three=org.apache.log4j.DailyRollingFileAppender
log4j.appender.three.File=${logpath}three.log
log4j.appender.three.DatePattern=${backup_pattern}
log4j.appender.three.layout=org.apache.log4j.PatternLayout
log4j.appender.three.layout.conversionPattern=${simple_pattern}

first time I use process appender is single logger and now i separate it to ONE, TWO and THREE logger. my processes executed by windows schedule every 1 minute.

So. I got Big problem I don't know why log4j cannot generate backup files. but when I execute manual by command line It's Ok.

+2  A: 

Is your log4j.properties file in the classpath when executed by the scheduler? I had a similar problem in the past, and it was due to the configuration file not being in the classpath.

You can include it in your process.jar file, or specify its location like this:

java -Dlog4j.configuration=file:///path/to/log4j.properties -jar process.jar one

David Crow
A: 

Many thanks, I will try again for your solution.

and Now My schedule executed my processes via bgprocess.bat

bgprocess.bat

@echo off
set CLASSPATH=.;%CLASSPATH%
set path=C:\j2sdk1.4.2\bin;%path%
javaw -jar process.jar %1

process.jar manifest.mf

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.4.2 (IBM Corporation)
Main-Class: process.Process
Class-Path: ./lib/Utility.jar ./lib/DB2LibRAD.jar ./lib/rowset.jar ./l
 ib/log4j-1.2.8.jar ./lib/com.ibm.mq.jar .

process directory

   - process.jar
   - bgprocess.bat
   - lib <dir>
               - log4j-1.2.8.jar
               - com.ibm.mq.jar
               - connector.jar
               - DB2LibRAD.jar
               - rowset.jar
               - Utility.jar                    
   - log <dir>
               - one.log
               - two.log
               - three.log
               - process.log

and all log files working normally but when pass backup time it will truncated and begin new log at first line.

Fuangwith S.
A: 

Appending should be the default, according to the javadocs, but it's worth specifying it in your config file to remove the ambiguity. With luck, it might fix your problem

log4j.appender.three.Append=true
skaffman