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)
|
||||
|
|
|
@ -21,20 +21,6 @@
|
|||
const hr =
|
||||
'---------------------------------------------------------------------------------'
|
||||
|
||||
export default {
|
||||
getColoredDateString: getColoredDateString,
|
||||
Log: Log,
|
||||
DebugLog: DebugLog,
|
||||
GetColor: GetColor,
|
||||
LogReq: LogReq,
|
||||
LogStat: LogStat,
|
||||
Load: Load,
|
||||
logHashed: logHashed,
|
||||
hr: hr,
|
||||
C: C,
|
||||
setNewLogfileName: setNewLogfileName,
|
||||
}
|
||||
|
||||
const DELIM = C('green') + '|' + C()
|
||||
|
||||
// import express from 'express'
|
||||
|
@ -50,7 +36,7 @@ const uvStatsFile = 'stats/uvstats'
|
|||
const nologFile = './nolog'
|
||||
|
||||
const colors = ['green', 'red', 'yellow', 'blue', 'magenta', 'cyan']
|
||||
let logFileName = utils.GetDateString(true)
|
||||
const logFileName = 'log'
|
||||
|
||||
const writeInterval = 10
|
||||
const debugLevel = parseInt(process.env.NS_LOGLEVEL) || 0
|
||||
|
@ -68,10 +54,6 @@ let writes = 0
|
|||
|
||||
let noLogips = []
|
||||
|
||||
function setNewLogfileName(): void {
|
||||
logFileName = utils.GetDateString(true)
|
||||
}
|
||||
|
||||
function getColoredDateString(): string {
|
||||
const date = new Date()
|
||||
const dateString = utils.GetDateString()
|
||||
|
@ -418,3 +400,19 @@ function C(color?: string): string {
|
|||
}
|
||||
return '\x1b[0m'
|
||||
}
|
||||
|
||||
export default {
|
||||
getColoredDateString: getColoredDateString,
|
||||
Log: Log,
|
||||
DebugLog: DebugLog,
|
||||
GetColor: GetColor,
|
||||
LogReq: LogReq,
|
||||
LogStat: LogStat,
|
||||
Load: Load,
|
||||
logHashed: logHashed,
|
||||
hr: hr,
|
||||
C: C,
|
||||
logFileName: logFileName,
|
||||
logDir: logDir,
|
||||
vlogDir: vlogDir,
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 4c4fb1dacce3306de27407b501000851822394a4
|
||||
Subproject commit e311b88508f0c77d6b97a4273e57aa5d656a1a64
|
Loading…
Add table
Add a link
Reference in a new issue