Changeset View
Changeset View
Standalone View
Standalone View
support/aphlict/server/lib/AphlictLog.js
| var JX = require('javelin').JX; | var JX = require('javelin').JX; | ||||
| var fs = require('fs'); | var fs = require('fs'); | ||||
| var util = require('util'); | var util = require('util'); | ||||
| JX.install('AphlictLog', { | JX.install('AphlictLog', { | ||||
| construct : function() { | construct: function() { | ||||
| this._writeToLogs = []; | this._writeToLogs = []; | ||||
| this._writeToConsoles = []; | this._writeToConsoles = []; | ||||
| }, | }, | ||||
| members : { | members: { | ||||
| _writeToConsoles : null, | _writeToConsoles: null, | ||||
| _writeToLogs : null, | _writeToLogs: null, | ||||
| addLogfile : function(path) { | addLogfile: function(path) { | ||||
| var options = { | var options = { | ||||
| flags: 'a', | flags: 'a', | ||||
| encoding: 'utf8', | encoding: 'utf8', | ||||
| mode: 066 | mode: 066 | ||||
| }; | }; | ||||
| var logfile = fs.createWriteSteam(path, options); | var logfile = fs.createWriteSteam(path, options); | ||||
| this._writeToLogs.push(logfile); | this._writeToLogs.push(logfile); | ||||
| return this; | return this; | ||||
| }, | }, | ||||
| addConsole : function(console) { | addConsole: function(console) { | ||||
| this._writeToConsoles.push(console); | this._writeToConsoles.push(console); | ||||
| return this; | return this; | ||||
| }, | }, | ||||
| log : function(pattern) { | log: function(pattern) { | ||||
| var str = util.format.apply(null, arguments); | var str = util.format.apply(null, arguments); | ||||
| var date = new Date().toLocaleString(); | var date = new Date().toLocaleString(); | ||||
| str = '[' + date + '] ' + str; | str = '[' + date + '] ' + str; | ||||
| var ii; | var ii; | ||||
| for (ii = 0; ii < this._writeToConsoles.length; ii++) { | for (ii = 0; ii < this._writeToConsoles.length; ii++) { | ||||
| this._writeToConsoles[ii].log(str); | this._writeToConsoles[ii].log(str); | ||||
| } | } | ||||
| Show All 9 Lines | |||||