Rotating and Purging Logs - Java Native OS

Java examples for Native OS:Log

Description

Rotating and Purging Logs

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.LogManager;

public class Main {
  public static void main(String[] args) throws IOException {

    loadLoggingConfiguration();

    Logger logger = LoggerFactory.getLogger("");
    logger.info("Logging for the first Time!");
    logger.warn("A warning to be had");
    logger.error("This is an error!");

    Logger rollingLogger = LoggerFactory.getLogger("rollingLogger");
    for (int i = 0; i < 5000; i++) {
      rollingLogger.info("Logging for an event with :" + i);
    }
  }

  private static void loadLoggingConfiguration() {
    FileInputStream ins = null;
    try {
      ins = new FileInputStream(new File("logging.properties"));
      LogManager.getLogManager().readConfiguration(ins);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Related Tutorials