summaryrefslogtreecommitdiff
path: root/script-beta/log.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-10 11:56:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-10 11:56:35 +0800
commit585dac714a2f6f197035e40701201d4f2474f616 (patch)
tree2f5b576cae4e8938d339af4e12c9f447a671711f /script-beta/log.lua
parent63896ba92a934bdb6a4952882f486d1389a92a67 (diff)
downloadlua-language-server-585dac714a2f6f197035e40701201d4f2474f616.zip
#243 日志增加一些检查
Diffstat (limited to 'script-beta/log.lua')
-rw-r--r--script-beta/log.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/script-beta/log.lua b/script-beta/log.lua
index 6af189dc..257ef7bb 100644
--- a/script-beta/log.lua
+++ b/script-beta/log.lua
@@ -48,9 +48,6 @@ local function pushLog(level, ...)
if not m.path then
return
end
- if m.size > m.maxSize then
- return
- end
local t = tablePack(...)
for i = 1, t.n do
t[i] = tostring(t[i])
@@ -87,6 +84,9 @@ function m.raw(thd, level, msg, source, currentline, clock)
if level == 'error' then
ioStdErr:write(msg .. '\n')
end
+ if m.size > m.maxSize then
+ return
+ end
init_log_file()
if not m.file then
return ''
@@ -103,10 +103,12 @@ function m.raw(thd, level, msg, source, currentline, clock)
else
buf = ('[%s.%03.f][%s]%s[#%d:%s:%s]: %s\n'):format(timestr, ms * 1000, level, agl, thd, trimSrc(source), currentline, msg)
end
- m.file:write(buf)
m.size = m.size + #buf
if m.size > m.maxSize then
+ m.file:write(buf:sub(1, m.size - m.maxSize))
m.file:write('[REACH MAX SIZE]')
+ else
+ m.file:write(buf)
end
return buf
end