Change logfile at runtime without modifying config

Max Berger October 11, 2019

Is it possible to change the location of the logfile created by custom scripts? I tried the following code without success:

import org.apache.log4j.Level
import org.apache.log4j.Logger
import org.apache.log4j.SimpleLayout
import org.apache.log4j.FileAppender

log.removeAllAppenders()
log.addAppender(new FileAppender(new SimpleLayout(),"qweasd.log",false))
log.setLevel(Level.DEBUG)
log.error("Test")

I know that the docs mention that you can define a custom FileAppender in something.properties, but I need a way to do this at runtime. If it makes any difference, I tested this snippet using the script console of a local instance of Jira provided by the ScriptRunner sample application. Also, I am aware that it is possible to just create a File and write to that, but I'd very much prefer the comfort of log4j.

1 answer

1 accepted

0 votes
Answer accepted
Max Berger October 14, 2019

The code I posted actually works. The issue was that scriptrunner-samples comes with a broken script-root-config which leads to the new log (and I suppose any other file you'd create as well) being created in

scriptrunner-samples\jira\target\container\tomcat8x\cargo-jira-home

Suggest an answer

Log in or Sign up to answer