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

com.slicklog.appenders.logback.LogbackInternalLogger Maven / Gradle / Ivy

Go to download

SlickLog.com logback appender. Allows to push your logs to the the SlickLog.com platform.

There is a newer version: 1.1.2
Show newest version
/*
 * Copyright (c) 2013. SlickLog.
 */
package com.slicklog.appenders.logback;

import ch.qos.logback.core.spi.ContextAware;
import com.slicklog.remotelogger.InternalLogger;

/**
 *
 * @author Torindo Nesci
 */
public class LogbackInternalLogger implements InternalLogger {

  private enum LogLevel {
    INFO,
    ERROR
  }
  
  private static final String FORMAT = "[%s] %s";
  private final ContextAware mLogger;
  private final boolean mLogEnabled;
  
  public LogbackInternalLogger(ContextAware logger, boolean logEnabled) {
    mLogger = logger;
    mLogEnabled = logEnabled;
  }

  @Override
  public void info(String format, Object... params) {
    log(LogLevel.INFO, format, params);
  }

  @Override
  public void error(String format, Object... params) {
    log(LogLevel.ERROR, format, params);
  }
  
  private void log(LogLevel level, String format, Object ... params) {
    if (!mLogEnabled) {
      return;
    }
    String thread = Thread.currentThread().getName();
    String msg = String.format(format, params);
    msg = String.format(FORMAT, thread, msg);
    switch(level) {
      case INFO:
        mLogger.addInfo(msg);
        break;
      case ERROR:
        mLogger.addError(msg);
        break;
      default:
        mLogger.addInfo(msg);
    }
  }

  @Override
  public boolean isLoggerEnabled() {
    return mLogEnabled;
  }
  
  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy