Skip to content
No description or website provided.
JavaScript Other
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
configuration
grunt-config
src
.gitignore
.travis.yml
Gruntfile.js
README.md
Vagrantfile
bower.json
development.html
package.json
staging.html

README.md

Frontier.js

Build Status

Utilities

Logging

Description

Name: logger

Path: kiichigo/utils/logger

Logging utility allows filtered logging, with control over level and filter visibility.

API

Logger module.
logger.filter(filterName)

Will retrieve an instance of Logger class with filterName. This is a multiton factory which will only create new instances when unmentioned filterName is requested.

var logger1 = logger.filter('some.filter'),
    logger2 = logger.filter('some.filter'),
    logger3 = logger.filter('another.filter');

console.assert(logger1 === logger2);
console.assert(logger1 !== logger3);
logger.config

Will configure logging in applciation, there is three properties in configuration object

  • enabled: Boolean, will togle all logs, if enabled === false all logs will be disabled. Default value is true.
  • ignoredFilters: Array<String>, will toggle loggers with filters added to ignoredFilters array off.
  • minLevel: Number, will disable all loggs that lower than level specified, where:

    • info is level 1.
    • log is level 2.
    • debug is level 3.
    • warn is level 4.
    • error is level 5.

    Default values are:

      ignoredFilters: [],
      minLevel: 0,
      enabled: true
    
logger.reset

Resets current configuration. This method will not delete instances of logger class.

Logger class

Logger class is multiton class, and can only be created via logger.filter method, and can't be created directly. Once created logger can be switched on and off via logger.config.

Eamples
define(['kiichigo/utils/Any', 'kiichigo/utils/logger'], function (Any, logger) {
    var log = logger.filter('myViewClass');

    return Any.extend({
        initialize: function (options) {
            log.info('initialized, status is {status}', options);
        }
    });
});
Logger.info(message, …parameters);
Logger.log(message, …parameters);
Logger.debug(message, …parameters);
Logger.warn(message, …parameters);
Logger.error(message, …parameters);

Outputs message with info, log, debug, warn or error severity (level 1, 2, 3, 4 or 5). message is string or interpolated string, parameters can be either a sequence of values, or an object.

  • If sequence of values is passed, {n} (where n >= 0)can be used to interpolate, over values passed in parameters.
  • If object is passed {propertyName} (where propertyName is name of a property on object passed as parameter) string will be interpolated with values of properties of the object.

Similary

Examples:
// Logging string.
myLogger.info('executing method');
// Outputs: executing method

// Logging interpolated strings.
myLogger.info('executing {0}()`, 'methodName');
// Outputs: executing methodName()

myLogger.info('User name is {name} and age is {age}', { name: 'Robert', age: '30' });
// Outputs: User name is Robert and age is 30

Something went wrong with that request. Please try again.