Skip to content

Instantly share code, notes, and snippets.

@angeloh
Created November 13, 2012 00:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angeloh/4062948 to your computer and use it in GitHub Desktop.
Save angeloh/4062948 to your computer and use it in GitHub Desktop.
MyLoggerJ.java to use with MyLoggerS.scala
package common;
import play.Logger.ALogger;
import play.api.Play;
public class MyLoggerJ {
private static final BLogger logger = of("application");
/**
* Obtain a logger instance.
*
* @param name name of the logger
* @return a logger
*/
public static BLogger of(String name) {
return new BLogger(MyLoggerS.apply(name));
}
/**
* Obtain a logger instance.
*
* @param clazz a class whose name will be used as logger name
* @return a logger
*/
public static BLogger of(Class<?> clazz) {
return new BLogger(MyLoggerS.apply(clazz));
}
/**
* Log a message with the DEBUG level.
*
* @param message message to log
*/
public static void debug(String message) {
logger.debug(message);
}
/**
* Log a message with the DEBUG level.
*
* @param message message to log
* @param error associated exception
*/
public static void debug(String message, Throwable error) {
logger.debug(message, error);
}
/**
* Typical logger interface
*/
public static class BLogger extends ALogger {
private final play.api.Logger logger;
public BLogger(play.api.Logger logger) {
super(logger);
this.logger = logger;
}
/**
* Logs a message with the DEBUG level.
*
* @param message Message to log
*/
@Override
public void debug(String message) {
if (Play.isTest(Play.current())) {
info(message);
} else {
logger.underlyingLogger().debug(message);
}
}
/**
* Logs a message with the DEBUG level, with the given error.
*
* @param message Message to log
* @param error associated exception
*/
@Override
public void debug(String message, Throwable error) {
if (Play.isTest(Play.current())) {
info(message, error);
} else {
logger.underlyingLogger().debug(message, error);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment