Mercurial Hosting > luan
diff src/luan/modules/logging/LuanLogger.java @ 1321:307e76ccd0d6
generalize separate logging
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 05 Feb 2019 22:36:55 -0700 |
parents | 1a68fc55a80c |
children | 11b7e11f9ed5 |
line wrap: on
line diff
--- a/src/luan/modules/logging/LuanLogger.java Mon Feb 04 20:18:51 2019 -0700 +++ b/src/luan/modules/logging/LuanLogger.java Tue Feb 05 22:36:55 2019 -0700 @@ -1,6 +1,11 @@ package luan.modules.logging; import org.apache.log4j.Logger; +import org.apache.log4j.LogManager; +import org.apache.log4j.Hierarchy; +import org.apache.log4j.Level; +import org.apache.log4j.spi.LoggerRepository; +import org.apache.log4j.spi.RootLogger; import luan.Luan; import luan.LuanState; import luan.LuanException; @@ -30,4 +35,31 @@ logger.debug( luan.toString(obj) ); } + + private static String KEY = "Logger.Repository"; + + public static LoggerRepository getLoggerRepository(LuanState luan) { + LoggerRepository lr = (LoggerRepository)luan.registry().get(KEY); + return lr != null ? lr : LogManager.getLoggerRepository(); + } + + public static void setLoggerRepository(LuanState luan,LoggerRepository lr) throws LuanException { + luan.registry().put(KEY,lr); + LuanTable module = (LuanTable)luan.require("luan:logging/Logging.luan"); + module.call( "init_root" ); + } + + public static void newLoggerRepository(LuanState luan) throws LuanException { + LoggerRepository lr = new Hierarchy(new RootLogger(Level.DEBUG)); + setLoggerRepository(luan,lr); + } + + public static Logger getRootLogger(LuanState luan) { + return getLoggerRepository(luan).getRootLogger(); + } + + public static Logger getLogger(LuanState luan,String name) { + return getLoggerRepository(luan).getLogger(name); + } + }