Context

Context

Working context, which stores all plugins and configrations, can generate multiple loggers. A context has two types of plugins:

  1. Handler: a handler recieve log info and process. For example, a FSHandler can persists log data onto file system with rolling datetime as fileanme. A log method passes log data to handlers through event emitter asynchronously, so that a compliated handler won't affect performance.
  2. Formatter: a formatter is used to render log text with raw log data. Most simple formatter is NativeFormatter, which only output with util.format shipped by Node.js.

By default, a context is equipped with a SimpleFormatter and FSHandler.

Constructor

new Context(optionsopt)

Default constructor

Parameters:
Name Type Attributes Description
options ContextOptions <optional>

contxt options

Source:

Members

(static) defaults :Object

Default method configs. See defaults.js for detailed config.

Type:
  • Object
Source:

(static) one :Context

Shared instance with default configuration

Type:
Source:

Methods

configure(options) → {Context}

Update context with options.

Parameters:
Name Type Description
options ContextOptions

contxt options

Source:
Returns:
  • current context
Type
Context

formatter(name) → {Formatter}

Get a registerd formatter by name. If not formatter has been defined before, a fallback formatter will be returned, which output nothing to stdout/stderr.

Parameters:
Name Type Description
name string

formatter name

Source:
Returns:
  • the formatter found
Type
Formatter

install(type, name, options) → {Context}

Setup a plugin

Parameters:
Name Type Description
type string

plugin type

name string

plugin name

options PluginOptions

plugin options

Source:
Returns:
  • context it self
Type
Context

logger(optionsopt) → {Logger}

Create a logger with options. A logger can have abitary log methods. By defualt, a logger only has info, debug, info, warn, error methods. Each method has its own attributes specified by LoggerOptions

Parameters:
Name Type Attributes Description
options LoggerOptions <optional>

options for a logger

Source:
Returns:
  • created logger
Type
Logger