Mercurial Hosting > luan
view src/luan/modules/logging/LuanLogger.java @ 1402:27efb1fcbcb5
move luan.lib to goodjava
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 17 Sep 2019 01:35:01 -0400 |
parents | cc0dbca576dc |
children | 219f2b937f2b |
line wrap: on
line source
package luan.modules.logging; import goodjava.logging.Logger; import goodjava.logging.LoggerFactory; import luan.Luan; import luan.LuanException; public final class LuanLogger { private final Logger logger; public LuanLogger(Luan luan,String name) { this.logger = getLogger(luan,name); } public void error(Object obj) throws LuanException { logger.error( Luan.luanToString(obj) ); } public void warn(Object obj) throws LuanException { logger.warn( Luan.luanToString(obj) ); } public void info(Object obj) throws LuanException { logger.info( Luan.luanToString(obj) ); } public void debug(Object obj) throws LuanException { logger.debug( Luan.luanToString(obj) ); } private static ThreadLocal<Luan> tl = new ThreadLocal<Luan>(); private static void init(Luan luan) { try { luan.require("luan:logging/Logging.luan"); // ensure initialization } catch(LuanException e) { throw new RuntimeException(e); } } public static Logger getLogger(Luan luan,String name) { init(luan); tl.set(luan); try { return LoggerFactory.getLogger(name); } finally { tl.remove(); } } public static Logger getLogger(Luan luan,Class cls) { init(luan); tl.set(luan); try { return LoggerFactory.getLogger(cls); } finally { tl.remove(); } } public static Luan luan() { return tl.get(); } }