Mercurial Hosting > luan
view src/luan/modules/logging/LuanLogger.java @ 1392:002152af497a
hosted postgres
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 06 Sep 2019 00:19:47 -0600 |
parents | 8b61c8c4e07a |
children | cc0dbca576dc |
line wrap: on
line source
package luan.modules.logging; import luan.lib.logging.Logger; import luan.lib.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>(); public static Logger getLogger(Luan luan,String name) { try { luan.require("luan:logging/Logging.luan"); // ensure initialization } catch(LuanException e) { throw new RuntimeException(e); } tl.set(luan); try { return LoggerFactory.getLogger(name); } finally { tl.remove(); } } public static Logger getLogger(Luan luan,Class cls) { tl.set(luan); try { return LoggerFactory.getLogger(cls); } finally { tl.remove(); } } public static Luan luan() { return tl.get(); } }