Skip to content

Instantly share code, notes, and snippets.

@nolawnchairs
Last active January 17, 2019 20:25
Show Gist options
  • Save nolawnchairs/052ce087f05e7fd1032ff9197459e364 to your computer and use it in GitHub Desktop.
Save nolawnchairs/052ce087f05e7fd1032ff9197459e364 to your computer and use it in GitHub Desktop.
Morphia binding for slf4j
package whatever;
import org.mongodb.morphia.logging.Logger;
import org.mongodb.morphia.logging.LoggerFactory;
import org.mongodb.morphia.logging.MorphiaLoggerFactory;
public class MorphiaLogger implements Logger {
private final org.slf4j.Logger logger;
static {
MorphiaLoggerFactory.reset();
MorphiaLoggerFactory.registerLogger(MorphiaLoggerFactoryImpl.class);
}
public MorphiaLogger(Class<?> aClass) {
this.logger = org.slf4j.LoggerFactory.getLogger(aClass);
}
@Override
public void debug(String s) {
logger.debug(s);
}
@Override
public void debug(String s, Object... objects) {
logger.debug(s, objects);
}
@Override
public void debug(String s, Throwable throwable) {
logger.debug(s, throwable);
}
@Override
public void error(String s) {
logger.error(s);
}
@Override
public void error(String s, Object... objects) {
logger.error(s, objects);
}
@Override
public void error(String s, Throwable throwable) {
logger.error(s, throwable);
}
@Override
public void info(String s) {
logger.info(s);
}
@Override
public void info(String s, Object... objects) {
logger.info(s, objects);
}
@Override
public void info(String s, Throwable throwable) {
logger.info(s, throwable);
}
@Override
public boolean isDebugEnabled() {
return false;
}
@Override
public boolean isErrorEnabled() {
return true;
}
@Override
public boolean isInfoEnabled() {
return true;
}
@Override
public boolean isTraceEnabled() {
return true;
}
@Override
public boolean isWarningEnabled() {
return true;
}
@Override
public void trace(String s) {
logger.trace(s);
}
@Override
public void trace(String s, Object... objects) {
logger.trace(s, objects);
}
@Override
public void trace(String s, Throwable throwable) {
logger.trace(s, throwable);
}
@Override
public void warning(String s) {
logger.warn(s);
}
@Override
public void warning(String s, Object... objects) {
logger.warn(s, objects);
}
@Override
public void warning(String s, Throwable throwable) {
logger.warn(s, throwable);
}
public static class MorphiaLoggerFactoryImpl implements LoggerFactory {
@Override
public Logger get(Class<?> aClass) {
return new MorphiaLogger(aClass);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment