var JX = require('javelin').JX;

var fs = require('fs');
var util = require('util');

JX.install('AphlictLog', {
  construct: function() {
    this._writeToLogs = [];
    this._writeToConsoles = [];
  },

  members: {
    _writeToConsoles: null,
    _writeToLogs: null,

    addLogfile: function(path) {
      var options = {
        flags: 'a',
        encoding: 'utf8',
        mode: 066
      };

      var logfile = fs.createWriteStream(path, options);

      this._writeToLogs.push(logfile);

      return this;
    },

    addConsole: function(console) {
      this._writeToConsoles.push(console);
      return this;
    },

    log: function() {
      var str = util.format.apply(null, arguments);
      var date = new Date().toLocaleString();
      str = '[' + date + '] ' + str;

      var ii;
      for (ii = 0; ii < this._writeToConsoles.length; ii++) {
        this._writeToConsoles[ii].log(str);
      }

      for (ii = 0; ii < this._writeToLogs.length; ii++) {
        this._writeToLogs[ii].write(str + '\n');
      }
    }

  }

});

var JX = require('javelin').JX;

var fs = require('fs');
var util = require('util');

JX.install('AphlictLog', {
  construct: function() {
    this._writeToLogs = [];
    this._writeToConsoles = [];
  },

  members: {
    _writeToConsoles: null,
    _writeToLogs: null,

    addLogfile: function(path) {
      var options = {
        flags: 'a',
        encoding: 'utf8',
        mode: 0664,
      };

      var logfile = fs.createWriteStream(path, options);

      this._writeToLogs.push(logfile);

      return this;
    },

    addConsole: function(console) {
      this._writeToConsoles.push(console);
      return this;
    },

    log: function() {
      var str = util.format.apply(null, arguments);
      var date = new Date().toLocaleString();
      str = '[' + date + '] ' + str;

      var ii;
      for (ii = 0; ii < this._writeToConsoles.length; ii++) {
        this._writeToConsoles[ii].log(str);
      }

      for (ii = 0; ii < this._writeToLogs.length; ii++) {
        this._writeToLogs[ii].write(str + '\n');
      }
    }

  }

});

Fix permissions on Aphlict log
Fix permissions on Aphlict log

Summary: Currently, the Aphlict server created the log file (if it doesn't exist) but then immediately fails with "Unable to open logfile". It seems that we don't set the permissions correctly.

Test Plan: Deleted log file and was able to start the Aphlict server.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11351
