Loggers

Loggers

Manages logger objects that can send log entries to the console, files, and AWS CloudWatch Logs

Constructor

new Loggers(options, levelsopt)

Source:
Parameters:
Name Type Attributes Description
options object
levels object <optional>

An object with properties levels and colors, both of which are objects whose keys are level names. This is the same object that is provided when creating Winston loggers. See an example at https://www.npmjs.com/package/winston#using-custom-logging-levels

Members

loggers :Loggers

Source:
Type:

parent :Loggers

Source:
Type:

ready :boolean

Indicates whether this object and its child loggers are ready to log messages. false when messages can not be logged because the logger is stopping or has been stopped.

Source:
Type:
  • boolean

winstonLevels :object

Maps level names to integers where lower values have higher severity

Source:
Type:
  • object

(static) defaultFileDirectories

Where log files are written

Source:

(static) defaultLevels

These follow npm levels wich are defined at https://github.com/winstonjs/winston#user-content-logging-levels with the addition of:

  • 'fail' : more severe than 'error'
  • 'db' : more severe than 'http'
  • 'more' : after 'info' ('more' noisy than 'info' but less noisy than 'verbose')

Custom levels can be provided to the Loggers class's constructor; however, the Loggers class assumes there is an 'error' level and the options model (via * the defaults) assumes the following levels exist: error, warn, debug.

See also https://github.com/winstonjs/winston#using-custom-logging-levels

Source:

(static) defaultMetaProperties

Default meta properties. Values are either null or a string containing the meta property name. For example, given the tuple a: 'b', property a is copied to meta.b.

Source:

Methods

category(categoryopt, backupCategoryopt) → {string}

Checks a category value

Source:
Parameters:
Name Type Attributes Description
category string <optional>
backupCategory string <optional>
Throws:

When this.options.unitTest is true, throws an exception if the category is not a string

Returns:
Type:
string

Returns the provided category if it is a truthy string; otherwise, returns the default category. Logs a warning when the value is truthy and its type is not a string.

child() → {object}

Creates a child logger

Source:
Returns:
Type:
object

context() → {object}

Accessor for context

Source:
Returns:
Type:
object

flush() → {Promise}

Flushes transports that support flushing, which is currently only CloudWatch.

Source:
Returns:
Type:
Promise

(async) flushCloudWatchTransports() → {Promise}

Flushes Cloudwatch transports

Source:
Returns:
Type:
Promise

isLevelEnabled(tagsOrNamedParametersopt, categoryopt) → {object}

Source:
Parameters:
Name Type Attributes Description
tagsOrNamedParameters * <optional>
category string <optional>
Returns:
Type:
object

If the message will be logged, returns an object with properties tags, logger, level, transports, and category. Otherwise, returns false.

levelEnabled(…argsopt)

Alias for isLevelEnabled

Source:
Parameters:
Name Type Attributes Description
args Array <optional>
<repeatable>

log(tagsopt, messageopt, dataopt, contextopt, categoryopt)

Sends a log entry to transports.

If tags is an Error object, ['error'] is used as the tags and the error is logged with message and data. If tags is an object with tags, message, data, and/or category properties, those properties are used as follows:

  1. tags = this.tags(tags.logLevel, tags.tags)
  2. message = tags.message
  3. data = tags.data
  4. context = tags.context
  5. category = tags.category
Source:
Parameters:
Name Type Attributes Description
tags * <optional>

See description

message * <optional>
data * <optional>
context * <optional>
category string <optional>

logger(categoryopt) → {Loggers|object}

Returns a logger associated with a category

Source:
Parameters:
Name Type Attributes Description
category string <optional>
Returns:
Type:
Loggers | object

(async) restart() → {Promise}

Restarts

Source:
Returns:
Type:
Promise

setLogger(categoryopt, loggeropt) → {Logger|undefined}

Associates a logger with a category

Source:
Parameters:
Name Type Attributes Description
category string <optional>
logger Loggers | object <optional>

If falsy, the category will not be associated with a logger.

Returns:
Type:
Logger | undefined

The stored logger

stack(nameopt) → {Stack}

Retrieves a named Stack instance

Source:
Parameters:
Name Type Attributes Description
name string <optional>
Returns:
Type:
Stack

start()

Starts the logger after the constructor or stop() is called

Source:

(async) stop() → {Promise}

Flushes loggers and stops them

Source:
Throws:
None
Returns:
Type:
Promise

tags(…argsopt) → {object}

Combines tags into a single tags object

Source:
Parameters:
Name Type Attributes Description
args Array <optional>
<repeatable>
Returns:
Type:
object

winstonLogger(categoryopt) → {object}

Returns a Winston logger associated with a category

Source:
Parameters:
Name Type Attributes Description
category string <optional>
Returns:
Type:
object

A Winston logger