comparison src/luan/modules/logging/LuanLogger.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 c88b486a9511
comparison
equal deleted inserted replaced
1332:11b7e11f9ed5 1333:25746915a241
1 package luan.modules.logging; 1 package luan.modules.logging;
2 2
3 import org.slf4j.Logger; 3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 4 import org.slf4j.LoggerFactory;
5 import luan.LuanState; 5 import luan.Luan;
6 import luan.LuanException; 6 import luan.LuanException;
7 7
8 8
9 public final class LuanLogger { 9 public final class LuanLogger {
10 private final Logger logger; 10 private final Logger logger;
11 11
12 public LuanLogger(LuanState luan,String name) { 12 public LuanLogger(Luan luan,String name) {
13 this.logger = getLogger(luan,name); 13 this.logger = getLogger(luan,name);
14 } 14 }
15 15
16 public void error(LuanState luan,Object obj) throws LuanException { 16 public void error(Luan luan,Object obj) throws LuanException {
17 logger.error( luan.toString(obj) ); 17 logger.error( luan.toString(obj) );
18 } 18 }
19 19
20 public void warn(LuanState luan,Object obj) throws LuanException { 20 public void warn(Luan luan,Object obj) throws LuanException {
21 logger.warn( luan.toString(obj) ); 21 logger.warn( luan.toString(obj) );
22 } 22 }
23 23
24 public void info(LuanState luan,Object obj) throws LuanException { 24 public void info(Luan luan,Object obj) throws LuanException {
25 logger.info( luan.toString(obj) ); 25 logger.info( luan.toString(obj) );
26 } 26 }
27 27
28 public void debug(LuanState luan,Object obj) throws LuanException { 28 public void debug(Luan luan,Object obj) throws LuanException {
29 logger.debug( luan.toString(obj) ); 29 logger.debug( luan.toString(obj) );
30 } 30 }
31 31
32 32
33 private static ThreadLocal<LuanState> tl = new ThreadLocal<LuanState>(); 33 private static ThreadLocal<Luan> tl = new ThreadLocal<Luan>();
34 34
35 public static Logger getLogger(LuanState luan,String name) { 35 public static Logger getLogger(Luan luan,String name) {
36 try { 36 try {
37 luan.require("luan:logging/Logging.luan"); // ensure initialization 37 luan.require("luan:logging/Logging.luan"); // ensure initialization
38 } catch(LuanException e) { 38 } catch(LuanException e) {
39 throw new RuntimeException(e); 39 throw new RuntimeException(e);
40 } 40 }
44 } finally { 44 } finally {
45 tl.remove(); 45 tl.remove();
46 } 46 }
47 } 47 }
48 48
49 public static LuanState luan() { 49 public static Luan luan() {
50 return tl.get(); 50 return tl.get();
51 } 51 }
52 } 52 }