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

com.microsoft.azure.sdk.iot.device.CustomLogger Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package com.microsoft.azure.sdk.iot.device;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class CustomLogger {

    private final Logger logger;
    private static final int CALLING_METHOD_NAME_DEPTH = 2;

    public CustomLogger(Class clazz)
    {
        logger = Logger.getLogger(clazz);
    }

    public void LogInfo(String message, Object...params)
    {
        if(logger.isEnabledFor(Level.INFO))
        {
            logger.info(String.format(message, params));
        }
    }

    public void LogDebug(String message, Object...params)
    {
        if(logger.isEnabledFor(Level.DEBUG))
        {
            logger.debug(String.format(message, params));
        }
    }

    public void LogDebug(String message, Throwable t, Object...params)
    {
        if(logger.isEnabledFor(Level.DEBUG))
        {
            logger.debug(String.format(message, params), t);
        }
    }

    public void LogTrace(String message, Object...params)
    {
        if(logger.isEnabledFor(Level.TRACE))
        {
            logger.trace(String.format(message, params));
        }
    }

    public void LogWarn(String message, Object...params)
    {
        if(logger.isEnabledFor(Level.WARN))
        {
            logger.warn(String.format(message, params));
        }
    }

    public void LogFatal(String message, Object...params)
    {
        if(logger.isEnabledFor(Level.FATAL))
        {
            logger.fatal(String.format(message, params));
        }
    }

    public void LogError(String message, Object...params)
    {
        if(logger.isEnabledFor(Level.ERROR))
        {
            logger.error(String.format(message, params));
        }
    }

    public void LogError(Throwable exception)
    {
        if(logger.isEnabledFor(Level.ERROR))
        {
            logger.error(exception);
        }
    }

    public String getMethodName()
    {
        return Thread.currentThread().getStackTrace()[CALLING_METHOD_NAME_DEPTH].getMethodName();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy