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

org.coos.messaging.util.DefaultLogger Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
/**
 * Copyright Telenor Objects AS
 */
/**
 * COOS - Connected Objects Operating System (www.connectedobjects.org).
 *
 * Copyright (C) 2009 Telenor ASA and Tellu AS. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program.  If not, see .
 *
 * You may also contact one of the following for additional information:
 * Telenor ASA, Snaroyveien 30, N-1331 Fornebu, Norway (www.telenor.no)
 * Tellu AS, Hagalokkveien 13, N-1383 Asker, Norway (www.tellu.no)
 */
package org.coos.messaging.util;

import java.util.Date;


/**
 * This class is a logger class used in environments where j2se is not available
 *
 * @author Knut Eilif Husa, Tellu AS
 *
 */
public class DefaultLogger implements Log {

    public static final int TRACE = 1;
    public static final int DEBUG = 2;
    public static final int INFO = 3;
    public static final int WARN = 4;
    public static final int ERROR = 5;
    public static final int FATAL = 6;
    private static int level = 1;

    private String name = "";

    public DefaultLogger(String loggerName) {
        this.name = loggerName;
    }

    public static int getLevel() {
        return level;
    }

    public static void setLevel(int level) {
        DefaultLogger.level = level;
    }

    public void setLoggerName(String loggerName) {
        name = loggerName;
    }

    public void trace(String arg) {

        if (level <= TRACE) {
            StringBuffer buf = new StringBuffer();
            buf.append(new Date());
            buf.append(":[TRACE]:");
            buf.append(arg);
            System.out.println(buf.toString());
        }

    }

    public void debug(String arg) {

        if (level <= DEBUG) {
            StringBuffer buf = new StringBuffer();
            buf.append(new Date());
            buf.append(":[DEBUG]:");
            buf.append(arg);
            System.out.println(buf.toString());
        }
    }

    public void info(String arg) {

        if (level <= INFO) {
            StringBuffer buf = new StringBuffer();
            buf.append(new Date());
            buf.append(":[INFO]:");
            buf.append(arg);
            System.out.println(buf.toString());
        }

    }

    public void warn(String arg) {

        if (level <= WARN) {
            StringBuffer buf = new StringBuffer();
            buf.append(new Date());
            buf.append(":[WARNING]:");
            buf.append(arg);
            System.out.println(buf.toString());
        }

    }


    public void warn(String arg, Exception e) {

        if (level <= WARN) {
            warn(arg);
            e.printStackTrace();
        }

    }

    public void error(String arg) {

        if (level <= ERROR) {
            StringBuffer buf = new StringBuffer();
            buf.append(new Date());
            buf.append(":[ERROR]:");
            buf.append(arg);
            System.err.println(buf.toString());
        }

    }

    public void error(String arg, Exception e) {

        if (level <= ERROR) {
            error(arg);
            e.printStackTrace();
        }

    }

    public void putMDC(String key, String value) {
        // No support for MDC
    }

    public void removeMDC(String key) {
        // No support for MDC
    }

    public boolean isInheritMDC() {

        // No support for MDC
        return false;
    }

    public void setInheritMDC(boolean inheritMDC) {
        // No support for MDC
    }

    public void debug(String msg, Exception e) {

        if (level <= DEBUG) {
            debug(msg);
            e.printStackTrace();
        }
    }

    public void info(String msg, Exception e) {

        if (level <= INFO) {
            info(msg);
            e.printStackTrace();
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy