-
New Feature
-
Resolution: Duplicate
-
Major
-
4.2.0
-
None
-
4.3 RC2
var AmetysHomeHelper = Java.type('AmetysHomeHelper'); var PatternLayout = Java.type('org.apache.log4j.PatternLayout'); var FileAppender = Java.type('org.apache.log4j.FileAppender'); var Level = Java.type('org.apache.log4j.Level'); var LogManager = Java.type('org.apache.log4j.LogManager'); function createNewLogFile(category, level) { var logger = LogManager.getLogger(category); logger.setAdditivity(false); logger.setLevel(Level.toLevel(level)); if (logger.getAppender(category) == null) { var filename = AmetysHomeHelper.getAmetysHome() + "/logs/" + category + ".log"; var layout = new PatternLayout("%d %-5p [%c] (%t;%X{requestURI}) %m%n"); var fileAppender = new FileAppender(layout, filename); fileAppender.activateOptions(); fileAppender.setName(category) logger.addAppender(fileAppender); } return logger; }
Use it like this:
var logger = createNewLogFile("script", "info"); logger.info("Blablabla...");
- Duplique
-
RUNTIME-3319 Create script to get a logger
- Closed