mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Logrotate redo
This commit is contained in:
parent
54a978b152
commit
070defecb6
3 changed files with 48 additions and 23 deletions
|
@ -237,10 +237,10 @@ function setLogTimer() {
|
|||
now.getDate() + 1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
1
|
||||
)
|
||||
logger.DebugLog(`Next daily action: ${night}`, 'daily', 1)
|
||||
const msToMidnight = night.getTime() - now.getTime()
|
||||
const msToMidnight = night.getTime() - now.getTime() + 1000
|
||||
logger.DebugLog(`msToMidnight: ${msToMidnight}`, 'daily', 1)
|
||||
logger.DebugLog(`Seconds To Midnight: ${msToMidnight / 1000}`, 'daily', 1)
|
||||
|
||||
|
@ -254,10 +254,38 @@ function setLogTimer() {
|
|||
|
||||
setTimeout(function() {
|
||||
LogTimerAction()
|
||||
rotateLog()
|
||||
setLogTimer()
|
||||
}, msToMidnight)
|
||||
}
|
||||
|
||||
function rotateLog() {
|
||||
const date = new Date()
|
||||
date.setDate(date.getDate() - 1)
|
||||
const fname =
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
('0' + (date.getMonth() + 1)).slice(-2) +
|
||||
'-' +
|
||||
('0' + date.getDate()).slice(-2) +
|
||||
' ' +
|
||||
('0' + date.getHours()).slice(-2) +
|
||||
':' +
|
||||
('0' + date.getMinutes()).slice(-2) +
|
||||
':' +
|
||||
('0' + date.getSeconds()).slice(-2)
|
||||
|
||||
const logFile = logger.logDir + logger.logFileName
|
||||
const vlogFile = logger.vlogDir + logger.logFileName
|
||||
|
||||
if (utils.FileExists(logFile)) {
|
||||
utils.CopyFile(logFile, logger.logDir + fname)
|
||||
}
|
||||
if (utils.FileExists(vlogFile)) {
|
||||
utils.CopyFile(vlogFile, logger.vlogDir + fname)
|
||||
}
|
||||
}
|
||||
|
||||
function LogTimerAction() {
|
||||
logger.DebugLog(`Running Log Timer Action`, 'daily', 1)
|
||||
Object.keys(modules).forEach((key) => {
|
||||
|
@ -280,7 +308,6 @@ function LogTimerAction() {
|
|||
const line =
|
||||
'==================================================================================================================================================='
|
||||
logger.Log(line)
|
||||
logger.setNewLogfileName()
|
||||
}
|
||||
|
||||
logger.Log('Node version: ' + process.version)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue