[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/support/aphlict/server/lib/ -> AphlictLog.js (source)

   1  var JX = require('javelin').JX;
   2  
   3  var fs = require('fs');
   4  var util = require('util');
   5  
   6  JX.install('AphlictLog', {
   7    construct: function() {
   8      this._writeToLogs = [];
   9      this._writeToConsoles = [];
  10    },
  11  
  12    members: {
  13      _writeToConsoles: null,
  14      _writeToLogs: null,
  15  
  16      addLogfile: function(path) {
  17        var options = {
  18          flags: 'a',
  19          encoding: 'utf8',
  20          mode: 066
  21        };
  22  
  23        var logfile = fs.createWriteSteam(path, options);
  24  
  25        this._writeToLogs.push(logfile);
  26  
  27        return this;
  28      },
  29  
  30      addConsole: function(console) {
  31        this._writeToConsoles.push(console);
  32        return this;
  33      },
  34  
  35      log: function() {
  36        var str = util.format.apply(null, arguments);
  37        var date = new Date().toLocaleString();
  38        str = '[' + date + '] ' + str;
  39  
  40        var ii;
  41        for (ii = 0; ii < this._writeToConsoles.length; ii++) {
  42          this._writeToConsoles[ii].log(str);
  43        }
  44  
  45        for (ii = 0; ii < this._writeToLogs.length; ii++) {
  46          this._writeToLogs[ii].write(str + '\n');
  47        }
  48      }
  49  
  50    }
  51  
  52  });


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1