devOpsTools
devOpsTools

Reputation: 190

Java program started using windows task scheduler but not creating log files in batch file folder

I have started java program (with batch file script) using Windows task scheduler. and in my log4.properties

log4j.rootLogger=ALL, file1
log4j.appender.file1=org.apache.log4j.RollingFileAppender
log4j.appender.file1.Threshold=INFO
log4j.appender.file1.File=personal-info.log 
log4j.appender.file1.MaxFileSize=10240KB
log4j.appender.file1.MaxBackupIndex=10
log4j.appender.file1.layout=org.apache.log4j.PatternLayout
log4j.appender.file1.layout.ConversionPattern = %d{ISO8601} %-5p [%t] [%F:%L] : %m%n
log4j.logger.com.personal=INFO,  file1
log4j.additivity.com.personal=false
log4j.additivity.org.springframework=false
log4j.additivity.org.jboss=false
log4j.additivity.org.hibernate=false
log4j.additivity.org.dozer=false

When I start my batch file from command line, this file gets created in same folder of batch file, but when I start it from windows task scheduler, it doesn't create log files either in batch file folder or anywhere else in machine.

One more thing, this task was started by other user, has anyone else has this issue before and solution is to provide physical path of folder in log4.properties?

Upvotes: 0

Views: 1646

Answers (3)

classicskids
classicskids

Reputation: 181

What worked for me was setting the current directory to be the location of my java (.jar) program, and then I saw the log file as if running manually from the command line.

I used a Powershell script to start my .jar file from Task Scheduler and so I set the current directory in the script using the Set-Location command on the line before.

If using a Window batch file you should also be able to set the current directory, see here.

Upvotes: 0

Brandon X.
Brandon X.

Reputation: 125

I have the same problem when the .bat file is executed by the Task Scheduler to start my small Java application. The log4j logfiles are simply not being created. But when I run the batch file from the command line everything works fine. As rishman suggested, there has to be something with PATH/classpath.

However you can save to file the logs generated by your batch file:

enter image description here

This will create a .log file in the location where the batch file is.

Upvotes: 0

Yann
Yann

Reputation: 144

You will encounter path and classpath issue with Task Scheduler. The user set to execute the scheduled task probably has a different PATH and classpath definition. The user set to execute the scheduled task has user privilege that could impact your batch execution. Your batch file has to set everything in order to run as you expect.

Hope this could help.

regards, Yann

Upvotes: 2

Related Questions