{"size": 2291, "ext": "js", "max_stars_repo_path": "src/foam/log/ConsoleLogger.js", "max_stars_repo_name": "mcarcaso/foam2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/foam/log/ConsoleLogger.js", "max_issues_repo_name": "mcarcaso/foam2", "max_issues_repo_issues_event_min_datetime": "2017-11-16T14:52:13.000Z", "max_issues_repo_issues_event_max_datetime": "2017-11-16T14:52:13.000Z", "max_forks_repo_path": "src/foam/log/ConsoleLogger.js", "max_forks_repo_name": "mcarcaso/foam2", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 26.0340909091, "max_line_length": 78, "alphanum_fraction": 0.6097773898}
/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

foam.CLASS({
  package: 'foam.log',
  name: 'ConsoleLogger',
  implements: [ 'foam.log.Logger' ],

  documentation: `Decorate contextual logging methods with log level (short
      name) and date string`,

  requires: [ 'foam.log.LogLevel' ],

  imports: [
    'debug as debug_',
    'log as log_',
    'info as info_',
    'warn as warn_',
    'error as error_'
  ],

  exports: [
    'debug',
    'log',
    'info',
    'warn',
    'error'
  ],

  properties: [
    {
      class: 'FunctionProperty',
      name: 'debug',
      factory: function() { return this.put.bind(this, this.LogLevel.DEBUG); }
    },
    {
      class: 'FunctionProperty',
      documentation: 'Synonym for "info".',
      name: 'log',
      factory: function() { return this.put.bind(this, this.LogLevel.INFO); }
    },
    {
      class: 'FunctionProperty',
      name: 'info',
      factory: function() { return this.put.bind(this, this.LogLevel.INFO); }
    },
    {
      class: 'FunctionProperty',
      name: 'warn',
      factory: function() { return this.put.bind(this, this.LogLevel.WARN); }
    },
    {
      class: 'FunctionProperty',
      name: 'error',
      factory: function() { return this.put.bind(this, this.LogLevel.ERROR); }
    },
    {
      class: 'FunctionProperty',
      name: 'getDateString',
      factory: function() {
        return function() { return (new Date()).toString(); };
      }
    }
  ],

  methods: [
    function put(logLevel) {
      var args = [ logLevel.shortName, '[' + this.getDateString() + ']' ]
          .concat(Array.from(arguments).slice(1));
      this[logLevel.consoleMethodName + '_'].apply(this, args);
    }
  ]
});
