tera/Source/core/log-strict.js

39 lines
1011 B
JavaScript
Raw Normal View History

2019-02-10 19:53:54 +00:00
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/
var fs = require('fs');
function CheckSizeLogFile(file_name,file_name_prev)
{
"use strict";
let FILE_NAME_LOG = file_name;
let FILE_NAME_LOG_PREV = file_name_prev;
setInterval(function ()
{
try
{
var stat = fs.statSync(FILE_NAME_LOG);
if(stat.size > MAX_SIZE_LOG)
{
if(fs.existsSync(FILE_NAME_LOG_PREV))
{
fs.unlinkSync(FILE_NAME_LOG_PREV);
}
fs.renameSync(FILE_NAME_LOG, FILE_NAME_LOG_PREV);
ToLog("truncate logfile ok");
}
}
catch(err)
{
}
}, 60000);
};
global.CheckSizeLogFile = CheckSizeLogFile;