Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1320:2c8d1d76a82a | 1321:307e76ccd0d6 |
---|---|
1 package luan.modules.logging; | 1 package luan.modules.logging; |
2 | 2 |
3 import org.apache.log4j.Logger; | 3 import org.apache.log4j.Logger; |
4 import org.apache.log4j.LogManager; | |
5 import org.apache.log4j.Hierarchy; | |
6 import org.apache.log4j.Level; | |
7 import org.apache.log4j.spi.LoggerRepository; | |
8 import org.apache.log4j.spi.RootLogger; | |
4 import luan.Luan; | 9 import luan.Luan; |
5 import luan.LuanState; | 10 import luan.LuanState; |
6 import luan.LuanException; | 11 import luan.LuanException; |
7 import luan.LuanTable; | 12 import luan.LuanTable; |
8 | 13 |
28 | 33 |
29 public void debug(LuanState luan,Object obj) throws LuanException { | 34 public void debug(LuanState luan,Object obj) throws LuanException { |
30 logger.debug( luan.toString(obj) ); | 35 logger.debug( luan.toString(obj) ); |
31 } | 36 } |
32 | 37 |
38 | |
39 private static String KEY = "Logger.Repository"; | |
40 | |
41 public static LoggerRepository getLoggerRepository(LuanState luan) { | |
42 LoggerRepository lr = (LoggerRepository)luan.registry().get(KEY); | |
43 return lr != null ? lr : LogManager.getLoggerRepository(); | |
44 } | |
45 | |
46 public static void setLoggerRepository(LuanState luan,LoggerRepository lr) throws LuanException { | |
47 luan.registry().put(KEY,lr); | |
48 LuanTable module = (LuanTable)luan.require("luan:logging/Logging.luan"); | |
49 module.call( "init_root" ); | |
50 } | |
51 | |
52 public static void newLoggerRepository(LuanState luan) throws LuanException { | |
53 LoggerRepository lr = new Hierarchy(new RootLogger(Level.DEBUG)); | |
54 setLoggerRepository(luan,lr); | |
55 } | |
56 | |
57 public static Logger getRootLogger(LuanState luan) { | |
58 return getLoggerRepository(luan).getRootLogger(); | |
59 } | |
60 | |
61 public static Logger getLogger(LuanState luan,String name) { | |
62 return getLoggerRepository(luan).getLogger(name); | |
63 } | |
64 | |
33 } | 65 } |