diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-05 22:47:52 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-05 22:47:52 +0800 |
commit | 8422502419f2a5138c2772aea60111fa7e9599aa (patch) | |
tree | a5ba32c15673d52f0cf301fa419f2bc7ba60733d | |
parent | 2b4a6564e39ee18791bedd9d0f79ff23f0d73188 (diff) | |
download | lua-language-server-8422502419f2a5138c2772aea60111fa7e9599aa.zip |
#1018 log level
-rw-r--r-- | .vscode/settings.json | 1 | ||||
-rw-r--r-- | main.lua | 4 | ||||
-rw-r--r-- | script/global.d.lua | 3 | ||||
-rw-r--r-- | script/log.lua | 21 |
4 files changed, 24 insertions, 5 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json index 0260f483..846e9d8c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,6 @@ "--preview", "--develop=true", "--dbgport=11413", + "--loglevel=trace", ] } @@ -58,6 +58,10 @@ collectgarbage('incremental', 120, 120, 0) ---@diagnostic disable-next-line: lowercase-global log = require 'log' log.init(ROOT, fs.path(LOGPATH) / 'service.log') +if LOGLEVEL then + log.level = tostring(LOGLEVEL):lower() +end + log.info('Lua Lsp startup, root: ', ROOT) log.debug('ROOT:', ROOT:string()) log.debug('LOGPATH:', LOGPATH) diff --git a/script/global.d.lua b/script/global.d.lua index 793f687d..56f3019f 100644 --- a/script/global.d.lua +++ b/script/global.d.lua @@ -46,3 +46,6 @@ CHECK = '' ---@type string | '"Error"' | '"Warning"' | '"Information"' | '"Hint"' CHECKLEVEL = 'Warning' + +---@type 'trace' | 'debug' | 'info' | 'warn' | 'error' +LOGLEVEL = 'warn' diff --git a/script/log.lua b/script/log.lua index 507051ae..2076348c 100644 --- a/script/log.lua +++ b/script/log.lua @@ -18,6 +18,14 @@ m.file = nil m.startTime = time.time() - monotonic() m.size = 0 m.maxSize = 100 * 1024 * 1024 +m.level = 'info' +m.levelMap = { + ['trace'] = 1, + ['debug'] = 2, + ['info'] = 3, + ['warn'] = 4, + ['error'] = 5, +} local function trimSrc(src) if src:sub(1, 1) == '@' then @@ -64,16 +72,16 @@ local function pushLog(level, ...) return text end -function m.info(...) - pushLog('info', ...) +function m.trace(...) + pushLog('trace', ...) end function m.debug(...) pushLog('debug', ...) end -function m.trace(...) - pushLog('trace', ...) +function m.info(...) + pushLog('info', ...) end function m.warn(...) @@ -85,6 +93,9 @@ function m.error(...) end function m.raw(thd, level, msg, source, currentline, clock) + if m.levelMap[level] < (m.levelMap[m.level] or m.levelMap['info']) then + return msg + end if level == 'error' then ioStdErr:write(msg .. '\n') if not m.firstError then @@ -92,7 +103,7 @@ function m.raw(thd, level, msg, source, currentline, clock) end end if m.size > m.maxSize then - return + return msg end init_log_file() local sec, ms = mathModf((m.startTime + clock) / 1000) |