Created
November 13, 2012 00:06
-
-
Save angeloh/4062948 to your computer and use it in GitHub Desktop.
MyLoggerJ.java to use with MyLoggerS.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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