summaryrefslogtreecommitdiff
path: root/log/log.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-02 19:49:27 +0800
committerchai <chaifix@163.com>2018-09-02 19:49:27 +0800
commitcf608a2af7106f9901bc0632c96594d2c938b416 (patch)
treead18a2edd0c8e1bc26e668d321d24af34ff3ac25 /log/log.lua
parent340861d2a5e4391e2f1671663f6812f1228a4c78 (diff)
*update
Diffstat (limited to 'log/log.lua')
-rw-r--r--log/log.lua53
1 files changed, 53 insertions, 0 deletions
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