Skip to content

Instantly share code, notes, and snippets.

@Faz95210
Created June 13, 2018 03:55
Show Gist options
  • Save Faz95210/76d91a5582cc577bbc216f343e261104 to your computer and use it in GitHub Desktop.
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
/*
* 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