diff --git a/lib/logs.js b/lib/logs.js index fd98e5a..1bf8f9c 100644 --- a/lib/logs.js +++ b/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() .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' }) diff --git a/lib/server.js b/lib/server.js index 6fd3ae7..0546171 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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') diff --git a/test/lib/logs.js b/test/lib/logs.js index 501df5a..a39f82e 100644 --- a/test/lib/logs.js +++ b/test/lib/logs.js @@ -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')) }) }) })