Logging Events Within Your Application - Java Native OS

Java examples for Native OS:Log

Description

Logging Events Within Your Application

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    public static void main (String[] args) {
        Main recipe = new Main();
        recipe.start();
    }

    private void start() {
        loadLoggingConfiguration();
        Logger logger = LoggerFactory.getLogger("recipeLogger");
        logger.info("Logging for the first Time!");
        logger.warn("A warning to be had");
        logger.error("This is an error!");
    }

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

}

Logging Levels

Logging Level Recommendation
Trace Least important of the logging events
Debug Use for extra information that helps with debugging
Info Use for everyday logging messages
Warn Use for recoverable issues
Error Use for exceptions, actual errors
Fatal Most important

Related Tutorials