-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.lua
More file actions
32 lines (27 loc) · 796 Bytes
/
helpers.lua
File metadata and controls
32 lines (27 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Logger setup with rotation in Lua
local logger = {}
local currentLogSize = 0
local maxLogSize = 1024 * 1024 -- 1MB
local logFilePath = 'app.log'
function logger.log(message)
local file = io.open(logFilePath, "a")
if file then
file:write(os.date("%Y-%m-%d %H:%M:%S") .. ' - ' .. message .. '\n')
file:close()
currentLogSize = currentLogSize + #message + 1
checkLogRotation()
end
end
function checkLogRotation()
if currentLogSize >= maxLogSize then
rotateLog()
end
end
function rotateLog()
local dateSuffix = os.date("%Y%m%d_%H%M%S")
local backupFilePath = 'app_' .. dateSuffix .. '.log'
os.rename(logFilePath, backupFilePath)
currentLogSize = 0
logger.log('Log rotated: ' .. backupFilePath)
end
return logger