A class helper for logging service.
/*
* Copyright (c) 2010-2011 Plugger Antonio Begue Ponce. All Rights Reserved.
*
* This file is part of Plugger Framework.
*
* Plugger Framework is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as published by
* the Free Software Foundation.
*
* Plugger Framework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plugger Framework. If not, see <http://www.gnu.org/licenses/>.
*/
//package org.plugger.util;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
/**
* A class helper for logging service.
*
* @author Antonio Begue
* @version $Revision: 1.0 $
*/
public class LoggerFactory {
private static Level logLevel = Level.INFO;
/**
* Return the common Logger.
* @return A Logger object.
*/
public static Logger getLogger() {
return getLogger("common");
}
/**
* Creates or return a specific Logger object.
* @param name The name of the Logger object.
* @return A Logger object.
*/
public static Logger getLogger(String name) {
Logger logger = Logger.getLogger(name);
FileHandler fh = null;
try {
// This block configure the logger with handler and formatter
fh = new FileHandler("uba_costos_" + name + ".log", true);
logger.addHandler(fh);
logger.setLevel(getLogLevel());
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
} catch (IOException ex) {
Logger.getLogger(LoggerFactory.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(LoggerFactory.class.getName()).log(Level.SEVERE, null, ex);
}
return logger;
}
/**
* Return the level of logging.
* @return the logLevel
*/
public static Level getLogLevel() {
return logLevel;
}
/**
* Set the level of logging.
* @param level the logLevel to set
*/
public static void setLogLevel(Level level) {
logLevel = level;
}
}
Related examples in the same category