Socket
Socket
Sign inDemoInstall

cagey-logger

Package Overview
Dependencies
8
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cagey-logger

Logger for the Cagey game framework


Version published
Weekly downloads
6
increased by20%
Maintainers
1
Install size
108 kB
Created
Weekly downloads
 

Readme

Source

The standard logger for the Cagey game framework

Greenkeeper badge

This is the standard logger for Cagey applications and plugins. It is heavily inspired by Bunyan, but differs in a few subtle ways:

  • Output format is configurable, instead of only JSON. The reason for this is that signals that kill the Bunyan CLI can cause it to shutdown before the main application itself, dropping final log messages.
  • Levels are mirrored after Syslog severity levels.
  • Meta data is not mixed with the rest of the data being logged, but has a dedicated data property.

Getting started

This installs cagey-logger into your project:

npm install cagey-logger --save

Levels

The severity levels are directly modeled after Syslog:

nrmethod namedescription
0log.emergency()System is unusable.
1log.alert()Action must be taken immediately. A condition that should be corrected immediately, such as a corrupted system database.
2log.critical()Critical conditions, such as hard device errors.
3log.error()Error conditions.
4log.warning()Warning conditions.
5log.notice()Normal but significant conditions. Conditions that are not error conditions, but that may require special handling.
6log.info()Informational messages.
7log.debug()Debug-level messages. Messages that contain information normally of use only when debugging a program.

When you set your logger to, for example, level 5 it will output all log entries between 0 and 5 (inclusive). In other words: from notices through emergencies.

API

factory

You can create a logger by calling the create factory function on the cagey-logger module:

const createLogger = require('cagey-logger').create;

const options = {
    name: 'myapp',   // the name of your application
    format: 'json',  // 'json' or 'human', defaults to 'human' when run inside a text terminal, 'json' otherwise
    level: 'debug'   // will only output this level and more severe levels
};

const data = {};     // properties you want all log messages to output

const log = createLogger(options, data);

In the API descriptions below, we will use debug(), but every level has its own method, as described above in "Levels".

log.debug(string message, [any ...args])

Logs a simple message, and applies any extra arguments to the message string using util.format.

Example:

log.debug('User "%s" logged in', username);

log.debug(Object|Array data, string message, [any ...args])

Logs a simple message, with data attached. The data may be an object or an array with any amount depth you may wish to apply. Certain property names will automatically apply specialized serializers that make the object more readable or parseable.

The built-in property serializers are:

  • req: HTTP IncomingMessage
  • error: an Error object with a stack and optional code are assumed

Example:

log.debug({ error }, 'User failed to "%s" log in', username);

log.child([Object data]) -> Logger

Creates a descendent logger, that contains the same configuration as the parent logger. You may add properties to add context for this logger that is always present in the output of the child logger.

License

MIT

Credit

Cagey is developed and maintained by Wizcorp.

Keywords

FAQs

Last updated on 20 Dec 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc