From cf608a2af7106f9901bc0632c96594d2c938b416 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 2 Sep 2018 19:49:27 +0800 Subject: *update --- log/init.lua | 55 ------------------------------------------------------- log/log.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 55 deletions(-) delete mode 100644 log/init.lua create mode 100644 log/log.lua (limited to 'log') diff --git a/log/init.lua b/log/init.lua deleted file mode 100644 index bfa2e4e..0000000 --- a/log/init.lua +++ /dev/null @@ -1,55 +0,0 @@ --- 不能使用 debug 命名模块,会冲突, --- 要使用其余名字比如 loghelper -local log = {} -io.stdout:setvbuf("no") - -local _format = "%c" -log.dateFormat = function(fmt) - _format = fmt -end - -log.LEVEL = { - INFO = 4, - DEBUG = 3, - WARN = 2, - ERROR = 1, - NONE = 0 -} - -local logTag = { - [log.LEVEL.INFO] = "[Info]", - [log.LEVEL.DEBUG] = "[Debug]", - [log.LEVEL.WARN] = "[Warn]", - [log.LEVEL.ERROR] = "[Error]", -} - -log.level = log.LEVEL.INFO - -log.strict = function(level) - log.level = level -end - -log.log = function(level, msg) - if level <= log.level then - local time = os.date(_format, os.time()) - print(time .. logTag[level] .. ":" .. msg) - end -end - -log.info = function(msg) - log.log(log.LEVEL.INFO, msg) -end - -log.debug = function(msg) - log.log(log.LEVEL.DEBUG, msg) -end - -log.warn = function(msg) - log.log(log.LEVEL.WARN, msg) -end - -log.error = function(msg) - log.log(log.LEVEL.ERROR, msg) -end - -return log \ No newline at end of file diff --git a/log/log.lua b/log/log.lua new file mode 100644 index 0000000..0c1d3bc --- /dev/null +++ b/log/log.lua @@ -0,0 +1,53 @@ +local log = {} +io.stdout:setvbuf("no") + +local _format = "%c" +log.dateFormat = function(fmt) + _format = fmt +end + +log.LEVEL = { + INFO = 4, + DEBUG = 3, + WARN = 2, + ERROR = 1, + NONE = 0 +} + +local logTag = { + [log.LEVEL.INFO] = "[Info]", + [log.LEVEL.DEBUG] = "[Debug]", + [log.LEVEL.WARN] = "[Warn]", + [log.LEVEL.ERROR] = "[Error]", +} + +log.level = log.LEVEL.INFO + +log.strict = function(level) + log.level = level +end + +log.log = function(level, msg) + if level <= log.level then + local time = os.date(_format, os.time()) + print(time .. logTag[level] .. ":" .. msg) + end +end + +log.info = function(msg) + log.log(log.LEVEL.INFO, msg) +end + +log.debug = function(msg) + log.log(log.LEVEL.DEBUG, msg) +end + +log.warn = function(msg) + log.log(log.LEVEL.WARN, msg) +end + +log.error = function(msg) + log.log(log.LEVEL.ERROR, msg) +end + +return log \ No newline at end of file -- cgit v1.1-26-g67d0