Created
June 13, 2018 03:55
-
-
Save Faz95210/76d91a5582cc577bbc216f343e261104 to your computer and use it in GitHub Desktop.
[Programmatically set log4J file output] Set in the program the file output of log4j logs #Java #Logs #Log4J
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Set logger's appender. If the logger is local, the change will only be local. | |
*/ | |
private void setAppender() { | |
SimpleLayout layout = new SimpleLayout(); | |
FileAppender appender = null; | |
try { | |
appender = new FileAppender(layout, "path/to/your/logs.log", true); //true = append; false = replace | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
logger.addAppender(appender); | |
logger.setLevel(Level.DEBUG); // Minimum Level to be logged | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment