All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aeontronix.commons.logging.LoggingUtils Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Copyright (c) 2014 Kloudtek Ltd
 */

package com.aeontronix.commons.logging;

import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Logging related utilities
 */
public class LoggingUtils {
    public static void setupSimpleLogging(Level lvl, boolean showLevel, boolean showTimestamp) {
        Logger logger = Logger.getLogger("");
        for (final Handler handler : logger.getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                final SimpleLogFormatter logFormatter = new SimpleLogFormatter();
                logFormatter.setShowLevel(showLevel);
                logFormatter.setShowTimestamp(showTimestamp);
                logFormatter.setSeparator(": ");
                handler.setFormatter(logFormatter);
            }
        }
        setLoggingLevel(lvl);
    }

    public static void setLoggingLevel(Level lvl) {
        Logger logger = Logger.getLogger("");
        logger.setLevel(lvl);
        for (final Handler handler : logger.getHandlers()) {
            handler.setLevel(lvl);
        }
    }

    public static void main(String[] args) {
        setLoggingLevel(Level.ALL);
        Logger logger = Logger.getLogger(LoggingUtils.class.getName());
        logger.fine("log fine");
        logger.info("log info");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy