mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Use server id instead of hardcoded arma3server prefix for logs on Linux
This commit is contained in:
parent
ae1de87ed3
commit
8537d50f20
18
lib/logs.js
18
lib/logs.js
@ -22,12 +22,12 @@ var Logs = function (config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logs.generateLogFileName = function (suffix) {
|
Logs.generateLogFileName = function (prefix, suffix) {
|
||||||
var dateStr = new Date().toISOString()
|
var dateStr = new Date().toISOString()
|
||||||
.replace(/:/g, '-') // Replace time dividers with dash
|
.replace(/:/g, '-') // Replace time dividers with dash
|
||||||
.replace(/T/, '_') // Remove date and time divider
|
.replace(/T/, '_') // Remove date and time divider
|
||||||
.replace(/\..+/, '') // Remove milliseconds
|
.replace(/\..+/, '') // Remove milliseconds
|
||||||
return 'arma3server_' + dateStr + '_' + suffix + '.rpt'
|
return prefix + '_' + dateStr + '_' + suffix + '.rpt'
|
||||||
}
|
}
|
||||||
|
|
||||||
Logs.prototype.delete = function (filename, callback) {
|
Logs.prototype.delete = function (filename, callback) {
|
||||||
@ -46,8 +46,8 @@ Logs.prototype.delete = function (filename, callback) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
Logs.prototype.generateLogFilePath = function (suffix) {
|
Logs.prototype.generateLogFilePath = function (prefix, suffix) {
|
||||||
return path.join(this.logsPath(), Logs.generateLogFileName(suffix))
|
return path.join(this.logsPath(), Logs.generateLogFileName(prefix, suffix))
|
||||||
}
|
}
|
||||||
|
|
||||||
Logs.prototype.logsPath = function () {
|
Logs.prototype.logsPath = function () {
|
||||||
@ -135,11 +135,11 @@ Logs.prototype.readLogFile = function (filename, callback) {
|
|||||||
fs.readFile(filename, callback)
|
fs.readFile(filename, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
Logs.prototype.logServerProcesses = function (serverProcess, headlessClientProcesses) {
|
Logs.prototype.logServerProcesses = function (prefix, serverProcess, headlessClientProcesses) {
|
||||||
var self = this
|
var self = this
|
||||||
this.logServerProcess(serverProcess, 'server')
|
this.logServerProcess(serverProcess, prefix, 'server')
|
||||||
headlessClientProcesses.forEach(function (headlessClientProcess, idx) {
|
headlessClientProcesses.forEach(function (headlessClientProcess, idx) {
|
||||||
self.logServerProcess(headlessClientProcess, 'hc_' + (idx + 1))
|
self.logServerProcess(headlessClientProcess, prefix, 'hc_' + (idx + 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
if (this.config.type === 'linux') {
|
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') {
|
if (this.config.type !== 'linux') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var logStream = fs.createWriteStream(this.generateLogFilePath(suffix), {
|
var logStream = fs.createWriteStream(this.generateLogFilePath(prefix, suffix), {
|
||||||
flags: 'a'
|
flags: 'a'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ Server.prototype.start = function () {
|
|||||||
|
|
||||||
this.startHeadlessClients()
|
this.startHeadlessClients()
|
||||||
|
|
||||||
this.logs.logServerProcesses(this.instance, this.headlessClientInstances)
|
this.logs.logServerProcesses(this.id, this.instance, this.headlessClientInstances)
|
||||||
|
|
||||||
this.emit('state')
|
this.emit('state')
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@ describe('Logs', function () {
|
|||||||
|
|
||||||
describe('generateLogFileName()', function () {
|
describe('generateLogFileName()', function () {
|
||||||
it('should generate valid file name', 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 () {
|
describe('generateLogFilePath()', function () {
|
||||||
it('should generate valid file path', 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'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user