001/*
002 * GWTEventService
003 * Copyright (c) 2011 and beyond, strawbill UG (haftungsbeschr?nkt)
004 *
005 * This is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU Lesser General Public License as
007 * published by the Free Software Foundation; either version 3 of
008 * the License, or (at your option) any later version.
009 * Other licensing for GWTEventService may also be possible on request.
010 * Please view the license.txt of the project for more information.
011 *
012 * This software is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this software; if not, write to the Free
019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021 */
022package de.novanic.eventservice.logger;
023
024import java.util.logging.Logger;
025import java.util.logging.Level;
026
027/**
028 * This {@link de.novanic.eventservice.logger.ServerLogger} uses the Java-Logging-API to log server messages.
029 * {@link de.novanic.eventservice.logger.ServerLogger} can be used to log at the server side.
030 *
031 * @author sstrohschein
032 * <br>Date: 15.08.2008
033 * <br>Time: 00:14:02
034 */
035public class DefaultServerLogger implements ServerLogger
036{
037    private static final String SERVER_LOG_PREFIX = "Server: ";
038
039    private final Logger LOG;
040
041    /**
042     * Creates a new DefaultServerLogger with the corresponding name.
043     * @param aLoggerName logger name
044     */
045    protected DefaultServerLogger(String aLoggerName) {
046        LOG = Logger.getLogger(aLoggerName);
047    }
048
049    /**
050     * Logs messages at the finest level.
051     * @param aMessage message to log
052     */
053    public void debug(String aMessage) {
054        log(Level.FINEST, aMessage);
055    }
056
057    /**
058     * Logs messages at the info level.
059     * @param aMessage message to log
060     */
061    public void info(String aMessage) {
062        log(Level.INFO, aMessage);
063    }
064
065    /**
066     * Logs messages at the severe level.
067     * @param aMessage message to log
068     */
069    public void error(String aMessage) {
070        log(Level.SEVERE, aMessage);
071    }
072
073    /**
074     * Logs messages at the severe level.
075     * @param aMessage message to log
076     * @param aThrowable throwable to log
077     */
078    public void error(String aMessage, Throwable aThrowable) {
079        if(LOG.isLoggable(Level.SEVERE)) {
080            LOG.log(Level.SEVERE, SERVER_LOG_PREFIX + aMessage, aThrowable);
081        }
082    }
083
084    /**
085     * Logs messages at a specified level.
086     * @param aLevel logging level
087     * @param aMessage message to log
088     */
089    public void log(Level aLevel, String aMessage) {
090        if(LOG.isLoggable(aLevel)) {
091            LOG.log(aLevel, SERVER_LOG_PREFIX + aMessage);
092        }
093    }
094}