{"size": 1357, "ext": "js", "max_stars_repo_path": "middleware/logger/transport-json.js", "max_stars_repo_name": "derdesign/protos", "max_stars_repo_stars_event_min_datetime": "2015-01-14T17:59:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-12T01:22:38.000Z", "max_issues_repo_path": "middleware/logger/transport-json.js", "max_issues_repo_name": "derdesign/protos", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "middleware/logger/transport-json.js", "max_forks_repo_name": "derdesign/protos", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.5396825397, "max_line_length": 78, "alphanum_fraction": 0.6094325718}

/* Logger » JSON Transport */

var app = protos.app;

function JSONTransport(evt, config, level, noAttach) {

  var self = this;

  this.className = this.constructor.name;

  // Set config if not set
  if (typeof config == 'string') {
    config = {filename: config}; // Accept filename as config
  } else if (typeof config == 'boolean') {
    config = {stdout: true}; // Accept boolean as config
  } else if (config.constructor !== Object) {
    return;
  }
  
  // Set config
  this.config = config;
  
  // Create write stream for json filename
  if (config.filename) var stream = app.logger.getFileStream(config.filename);

  var logEvent = evt + '_json';
  
  // Set write method
  this.write = function(log, data) {
    
    if (typeof log !== 'object') {
      log = {
        level: level,
        host: app.hostname,
        date: new Date().toGMTString(),
        msg: data[0]
      }
    }
    
    app.emit(logEvent, log)
    
    var json = JSON.stringify(log);
    
    if (stream) stream.write(json+'\n', 'utf8');
    
    if (config.stdout) console.log(json);
    
    for (var transport in self.otherTransports) {
      self.otherTransports[transport].write(json, data, log);
    }

  }

  if (!noAttach) app.on(evt, this.write);
  
}

JSONTransport.prototype.write = function(log, data) {
  // Interface
}

module.exports = JSONTransport;