Mercurial Hosting > luan
changeset 374:538c19ad1272
simplify logging
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 17 Apr 2015 18:03:26 -0600 |
parents | 571057b1666b |
children | e2e70d27c258 |
files | .hgignore logging/src/luan/modules/logging/Logging.luan logging/src/luan/modules/logging/LuanLogger.java |
diffstat | 3 files changed, 7 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
diff -r 571057b1666b -r 538c19ad1272 .hgignore --- a/.hgignore Fri Apr 17 15:14:44 2015 -0600 +++ b/.hgignore Fri Apr 17 18:03:26 2015 -0600 @@ -6,3 +6,4 @@ build Version.luan mine +*.bck
diff -r 571057b1666b -r 538c19ad1272 logging/src/luan/modules/logging/Logging.luan --- a/logging/src/luan/modules/logging/Logging.luan Fri Apr 17 15:14:44 2015 -0600 +++ b/logging/src/luan/modules/logging/Logging.luan Fri Apr 17 18:03:26 2015 -0600 @@ -4,7 +4,6 @@ local ConsoleAppender = require "java:org.apache.log4j.ConsoleAppender" local Level = require "java:org.apache.log4j.Level" local RollingFileAppender = require "java:org.apache.log4j.RollingFileAppender" -local LuanLogger = require "java:luan.modules.logging.LuanLogger" layout = "%d %-5p %c - %m%n" @@ -55,7 +54,12 @@ local function to_luan_logger(log4j_logger) - local tbl = LuanLogger.new(log4j_logger).table() + local tbl = {} + + tbl.error = log4j_logger.error + tbl.warn = log4j_logger.warn + tbl.info = log4j_logger.info + tbl.debug = log4j_logger.debug function tbl.get_level() local level = log4j_logger.getLevel()
diff -r 571057b1666b -r 538c19ad1272 logging/src/luan/modules/logging/LuanLogger.java --- a/logging/src/luan/modules/logging/LuanLogger.java Fri Apr 17 15:14:44 2015 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -package luan.modules.logging; - -import org.apache.log4j.Logger; -import luan.Luan; -import luan.LuanState; -import luan.LuanException; -import luan.LuanTable; -import luan.LuanJavaFunction; - - -public final class LuanLogger { - private final Logger logger; - - public LuanLogger(Logger logger) { - this.logger = logger; - } - - public void error(LuanState luan,Object obj) throws LuanException { - logger.error( luan.toString(obj) ); - } - - public void warn(LuanState luan,Object obj) throws LuanException { - logger.warn( luan.toString(obj) ); - } - - public void info(LuanState luan,Object obj) throws LuanException { - logger.info( luan.toString(obj) ); - } - - public void debug(LuanState luan,Object obj) throws LuanException { - logger.debug( luan.toString(obj) ); - } - - public LuanTable table() { - LuanTable tbl = Luan.newTable(); - try { - tbl.put( "error", new LuanJavaFunction( - LuanLogger.class.getMethod( "error", LuanState.class, Object.class ), this - ) ); - tbl.put( "warn", new LuanJavaFunction( - LuanLogger.class.getMethod( "warn", LuanState.class, Object.class ), this - ) ); - tbl.put( "info", new LuanJavaFunction( - LuanLogger.class.getMethod( "info", LuanState.class, Object.class ), this - ) ); - tbl.put( "debug", new LuanJavaFunction( - LuanLogger.class.getMethod( "debug", LuanState.class, Object.class ), this - ) ); - } catch(NoSuchMethodException e) { - throw new RuntimeException(e); - } - return tbl; - } -}