diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/config.lua | 1 | ||||
-rw-r--r-- | server/src/log.lua | 47 |
2 files changed, 36 insertions, 12 deletions
diff --git a/server/src/config.lua b/server/src/config.lua index c8d47b2f..2c18d0d0 100644 --- a/server/src/config.lua +++ b/server/src/config.lua @@ -65,6 +65,7 @@ local function setConfig(self, config) end end end + log.debug('配置更新:', table.dump(Config)) end) end diff --git a/server/src/log.lua b/server/src/log.lua index c4fa9461..5c04cdb9 100644 --- a/server/src/log.lua +++ b/server/src/log.lua @@ -13,6 +13,22 @@ local function trim_src(src) return src end +local function init_log_file() + if not log.file then + log.file = io.open(log.path, 'w') + if not log.file then + return + end + log.file:write('') + log.file:close() + log.file = io.open(log.path, 'ab') + if not log.file then + return + end + log.file:setvbuf 'no' + end +end + local function push_log(level, ...) if not log.path then return @@ -28,18 +44,9 @@ local function push_log(level, ...) if level == 'error' then str = str .. '\n' .. debug.traceback(nil, 3) end + init_log_file() if not log.file then - log.file = io.open(log.path, 'w') - if not log.file then - return - end - log.file:write('') - log.file:close() - log.file = io.open(log.path, 'ab') - if not log.file then - return - end - log.file:setvbuf 'no' + return end local sec, ms = math.modf(log.start_time + os.clock()) local timestr = os.date('%Y-%m-%d %H:%M:%S', sec) @@ -79,13 +86,29 @@ function log.error(...) end function log.init(root, path) + local lastBuf + if log.file then + log.file:close() + log.file = nil + local file = io.open(log.path, 'rb') + if file then + lastBuf = file:read 'a' + file:close() + end + end log.path = path:string() log.prefix_len = #root:string() + 3 - log.file = nil log.size = 0 if not fs.exists(path:parent_path()) then fs.create_directories(path:parent_path()) end + if lastBuf then + init_log_file() + if log.file then + log.file:write(lastBuf) + log.size = log.size + #lastBuf + end + end end return log |