0.2.3 • Published 12 years ago

nodify-logger v0.2.3

Weekly downloads
1
License
-
Repository
-
Last release
12 years ago

nodify-logger

Simple Logging facility inspired by VMS MESSAGE.

Installation

The easiest way to install this package is to use npm:

If you want to check out the source, use the git command:

Usage

Initialization

After importing the nodify-logger package, create a logging factory by using the createInstance() method. The first parameter to this call is an options object containing the following items:

  • facility - a facility name (required)
  • emitter - a function to use to write the log message (optional, defaults to util.debug)
  • messages - a map of severities / messages (optional)
  • messagesPath - the name of a file containing the map of severities / messages (optional)

The second parameter is a callback with three parameters:

  • log_function - a function used to log a message
  • messages - an object whose keys are message abbreviations derived from the messages object from the options
  • log_instance - the logger instance, in case you want to call it directly

Here is a simple example for a facility called PROXY:

Logging a message

Use the log_function parameter passed into the createInstance() callback to log messages. Parameters can be added to messages that require them:

var logger = require( 'nodify-logger' );
var logger_options = {
  facility: 'TEST',
  messages: {
    I: {
      simple: "I am a simple message",
      formats: "I am a message that takes a parameter: %s",
      formatd: "I am a message that takes a numeric parameter: %d"
    }
  }
};

logger.createInstance( logger_options, function ( l, TEST, log ) {
  l( TEST.I_SIMPLE );
  l( TEST.I_FORMATS, "w00t!" );
  l( TEST.I_FORMATD, 1337 );
} );</pre>
0.2.3

12 years ago

0.2.2

12 years ago

0.2.1

12 years ago

0.0.1

12 years ago