com.slicklog.appenders.logback.LogbackInternalLogger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of logbackappender Show documentation
Show all versions of logbackappender Show documentation
SlickLog.com logback appender.
Allows to push your logs to the the SlickLog.com platform.
/*
* 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;
}
}