Mercurial Hosting > luan
comparison src/luan/modules/logging/Log4j.java @ 1333:25746915a241
merge Luan and LuanState
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 12 Feb 2019 22:33:40 -0700 |
parents | 11b7e11f9ed5 |
children | e0cf0d108a77 |
comparison
equal
deleted
inserted
replaced
1332:11b7e11f9ed5 | 1333:25746915a241 |
---|---|
5 import org.apache.log4j.Hierarchy; | 5 import org.apache.log4j.Hierarchy; |
6 import org.apache.log4j.Level; | 6 import org.apache.log4j.Level; |
7 import org.apache.log4j.spi.LoggerRepository; | 7 import org.apache.log4j.spi.LoggerRepository; |
8 import org.apache.log4j.spi.RootLogger; | 8 import org.apache.log4j.spi.RootLogger; |
9 import org.apache.log4j.spi.RepositorySelector; | 9 import org.apache.log4j.spi.RepositorySelector; |
10 import luan.LuanState; | 10 import luan.Luan; |
11 import luan.LuanException; | 11 import luan.LuanException; |
12 import luan.LuanTable; | 12 import luan.LuanTable; |
13 | 13 |
14 | 14 |
15 public final class Log4j { | 15 public final class Log4j { |
16 private static String KEY = "Logger.Repository"; | 16 private static String KEY = "Logger.Repository"; |
17 | 17 |
18 public static void newLoggerRepository(LuanState luan) throws LuanException { | 18 public static void newLoggerRepository(Luan luan) throws LuanException { |
19 LoggerRepository lr = new Hierarchy(new RootLogger(Level.DEBUG)); | 19 LoggerRepository lr = new Hierarchy(new RootLogger(Level.DEBUG)); |
20 luan.registry().put(KEY,lr); | 20 luan.registry().put(KEY,lr); |
21 LuanTable module = (LuanTable)luan.require("luan:logging/Log4j.luan"); | 21 LuanTable module = (LuanTable)luan.require("luan:logging/Log4j.luan"); |
22 module.call( "init_root" ); | 22 module.call( "init_root" ); |
23 } | 23 } |
24 | 24 |
25 private static final LoggerRepository defaultLoggerRepository = LogManager.getLoggerRepository(); | 25 private static final LoggerRepository defaultLoggerRepository = LogManager.getLoggerRepository(); |
26 | 26 |
27 private static LoggerRepository getLoggerRepository(LuanState luan) { | 27 private static LoggerRepository getLoggerRepository(Luan luan) { |
28 LoggerRepository lr = (LoggerRepository)luan.registry().get(KEY); | 28 LoggerRepository lr = (LoggerRepository)luan.registry().get(KEY); |
29 return lr != null ? lr : defaultLoggerRepository; | 29 return lr != null ? lr : defaultLoggerRepository; |
30 } | 30 } |
31 | 31 |
32 static { | 32 static { |
33 LogManager.setRepositorySelector( new RepositorySelector() { | 33 LogManager.setRepositorySelector( new RepositorySelector() { |
34 public LoggerRepository getLoggerRepository() { | 34 public LoggerRepository getLoggerRepository() { |
35 LuanState luan = LuanLogger.luan(); | 35 Luan luan = LuanLogger.luan(); |
36 return luan==null ? defaultLoggerRepository : Log4j.getLoggerRepository(luan); | 36 return luan==null ? defaultLoggerRepository : Log4j.getLoggerRepository(luan); |
37 } | 37 } |
38 }, new Object() ); | 38 }, new Object() ); |
39 } | 39 } |
40 | 40 |
41 public static Logger getRootLogger(LuanState luan) { | 41 public static Logger getRootLogger(Luan luan) { |
42 return getLoggerRepository(luan).getRootLogger(); | 42 return getLoggerRepository(luan).getRootLogger(); |
43 } | 43 } |
44 | 44 |
45 public static Logger getLogger(LuanState luan,String name) { | 45 public static Logger getLogger(Luan luan,String name) { |
46 return getLoggerRepository(luan).getLogger(name); | 46 return getLoggerRepository(luan).getLogger(name); |
47 } | 47 } |
48 } | 48 } |