Skip to content

Instantly share code, notes, and snippets.

@sathishjayapal
Created August 28, 2021 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sathishjayapal/7d17032fbce086592177d3be567f9f22 to your computer and use it in GitHub Desktop.
Save sathishjayapal/7d17032fbce086592177d3be567f9f22 to your computer and use it in GitHub Desktop.
Java16 Logging Gist
package me.sathish;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
public class LoggingSample {
private static Logger logger = Logger.getLogger("me.sathish.package");
private static FileHandler fh;
private static FileHandler ch;
static {
try {
fh = new FileHandler("mylog.txt");
ch = new FileHandler("Secondfile.txt");
} catch (IOException e) {
logger.log(Level.SEVERE, "Logging file is not found");
}
}
public static void main(String[] args) {
int start = 5;
int counter = 0;
logger.addHandler(fh);
logger.setLevel(Level.ALL);
for (int i = 0; i < start; i++) {
if (i == 3) {
logger.addHandler(ch);
logger.setLevel(Level.ALL);
}
logger.log(Level.SEVERE, "This is the counter " + counter++);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment