Use server id instead of hardcoded arma3server prefix for logs on Linux

This commit is contained in:
Björn Dahlgren 2021-07-10 14:04:14 +02:00
parent ae1de87ed3
commit 8537d50f20
3 changed files with 12 additions and 12 deletions

View File

@ -22,12 +22,12 @@ var Logs = function (config) {
}
}
Logs.generateLogFileName = function (suffix) {
Logs.generateLogFileName = function (prefix, suffix) {
var dateStr = new Date().toISOString()
.replace(/:/g, '-') // Replace time dividers with dash
.replace(/T/, '_') // Remove date and time divider
.replace(/\..+/, '') // Remove milliseconds
return 'arma3server_' + dateStr + '_' + suffix + '.rpt'
return prefix + '_' + dateStr + '_' + suffix + '.rpt'
}
Logs.prototype.delete = function (filename, callback) {
@ -46,8 +46,8 @@ Logs.prototype.delete = function (filename, callback) {
})
}
Logs.prototype.generateLogFilePath = function (suffix) {
return path.join(this.logsPath(), Logs.generateLogFileName(suffix))
Logs.prototype.generateLogFilePath = function (prefix, suffix) {
return path.join(this.logsPath(), Logs.generateLogFileName(prefix, suffix))
}
Logs.prototype.logsPath = function () {
@ -135,11 +135,11 @@ Logs.prototype.readLogFile = function (filename, callback) {
fs.readFile(filename, callback)
}
Logs.prototype.logServerProcesses = function (serverProcess, headlessClientProcesses) {
Logs.prototype.logServerProcesses = function (prefix, serverProcess, headlessClientProcesses) {
var self = this
this.logServerProcess(serverProcess, 'server')
this.logServerProcess(serverProcess, prefix, 'server')
headlessClientProcesses.forEach(function (headlessClientProcess, idx) {
self.logServerProcess(headlessClientProcess, 'hc_' + (idx + 1))
self.logServerProcess(headlessClientProcess, prefix, 'hc_' + (idx + 1))
})
if (this.config.type === 'linux') {
@ -147,12 +147,12 @@ Logs.prototype.logServerProcesses = function (serverProcess, headlessClientProce
}
}
Logs.prototype.logServerProcess = function (serverProcess, suffix) {
Logs.prototype.logServerProcess = function (serverProcess, prefix, suffix) {
if (this.config.type !== 'linux') {
return
}
var logStream = fs.createWriteStream(this.generateLogFilePath(suffix), {
var logStream = fs.createWriteStream(this.generateLogFilePath(prefix, suffix), {
flags: 'a'
})

View File

@ -184,7 +184,7 @@ Server.prototype.start = function () {
this.startHeadlessClients()
this.logs.logServerProcesses(this.instance, this.headlessClientInstances)
this.logs.logServerProcesses(this.id, this.instance, this.headlessClientInstances)
this.emit('state')

View File

@ -19,13 +19,13 @@ describe('Logs', function () {
describe('generateLogFileName()', function () {
it('should generate valid file name', function () {
Logs.generateLogFileName('test').should.eql('arma3server_2015-10-21_19-28-32_test.rpt')
Logs.generateLogFileName('prefix', 'suffix').should.eql('prefix_2015-10-21_19-28-32_suffix.rpt')
})
})
describe('generateLogFilePath()', function () {
it('should generate valid file path', function () {
logs.generateLogFilePath('test').should.eql(path.join('/tmp', 'logs', 'arma3server_2015-10-21_19-28-32_test.rpt'))
logs.generateLogFilePath('prefix', 'suffix').should.eql(path.join('/tmp', 'logs', 'prefix_2015-10-21_19-28-32_suffix.rpt'))
})
})
})