Skip to content

Node.js library for logging to LogDNA

License

Notifications You must be signed in to change notification settings

6RiverSystems/logdna-nodejs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js library for logging to LogDNA

Build Status Known Vulnerabilities

===

Install

$ npm install logdna

Setup

var Logger = require('logdna');
var options = {
    hostname: myHostname,
    ip: ipAddress,
    mac: macAddress,
    app: appName
};

// Defaults to false, when true ensures meta object will be searchable
options.index_meta = true;

// Define a singleton instance
var logger = Logger.setupDefaultLogger(apikey, options);

// Create multiple loggers with different options
var logger = Logger.createLogger(apikey, options);

Required

Optional

  • Hostname - (String) - max length 32 chars
  • MAC Address - (String)
  • IP Address - (String)
  • Max Length - (Boolean) - formatted as options.max_length
  • Index Meta - (Boolean) - formatted as options.index_meta

Usage

After initial setup, logging is as easy as:

// Simplest use case
logger.log('My Sample Log Line');

// Add a custom level
logger.log('My Sample Log Line', 'MyCustomLevel');

// Include an App name with this specific log
logger.log('My Sample Log Line', { level: 'Warn', app: 'myAppName'});

// Pass any associated objects along for context
var context = {
    foo: 'bar',
    nested: { 
      nest1: 'nested text'
    }
}

var opts = {
  level: 'warn',
  context: context
}

logger.log('My Sample Log Line', opts);

For more options, this module also offers:

// We support the following six levels
logger.info('My Sample Log Line');
logger.warn('My Sample Log Line');
logger.debug('My Sample Log Line');
logger.error('My Sample Log Line');
logger.fatal('My Sample Log Line');

// Functions above also accept additional options
logger.trace('My Sample Log Line', { app: 'myAppName'});

var opts = {
  level: trace,
  context: {
    foo: 'bar',
    nested: { 
      nest1: 'nested text'
    }
  }
}

// Functions above also pass any associated objects along for context
logger.trace('My Sample Log Line', opts);

API

createLogger(key, [options])

key

Required
Type: String
Values: YourAPIKey

The LogDNA API Key associated with your account.

options

app

Optional
Type: String
Default: ''
Values: YourCustomApp
Max Length: 32

The default app passed along with every log sent through this instance.

hostname

Optional
Type: String
Default: ''
Values: YourCustomHostname
Max Length: 32

The default hostname passed along with every log sent through this instance.

index_meta

Optional
Type: Boolean
Default: false

We allow meta objects to be passed with each line. By default these meta objects will be stringified and will not be searchable, but will be displayed for informational purposes.

If this option is turned to true then meta objects will be parsed and will be searchable up to three levels deep. Any fields deeper than three levels will be stringified and cannot be searched.

WARNING When this option is true, your metadata objects across all types of log messages MUST have consistent types or log entries will be silently dropped!

ip

Optional
Type: String
Default: ''
Values: 10.0.0.1

The default IP Address passed along with every log sent through this instance.

level

Optional
Type: String
Default: Info
Values: Debug, Trace, Info, Warn, Error, Fatal, YourCustomLevel
Max Length: 32

The default level passed along with every log sent through this instance.

mac

Optional
Type: String
Default: ''
Values: C0:FF:EE:C0:FF:EE

The default MAC Address passed along with every log sent through this instance.

max_length

Optional
Type: Boolean
Default: true

By default the line has a maximum length of 32000 chars, this can be turned off with the value false.

timeout

Optional
Type: Integer
Default: 180000
Max Value: 300000

The length of the timeout on the POST request that is sent to LogDNA.

log(line, [options])

line

Required
Type: String
Default: ''
Max Length: 32000

The line which will be sent to the LogDNA system.

options

level

Optional
Type: String
Default: Info
Values: Debug, Trace, Info, Warn, Error, Fatal, YourCustomLevel
Max Length: 32

The level passed along with this log line.

app

Optional
Type: String
Default: ''
Values: YourCustomApp
Max Length: 32

The app passed along with this log line.

context

Optional
Type: JSON
Default: null

A meta object for additional context about the log line that is passed.

index_meta

Optional
Type: Boolean
Default: false

We allow meta objects to be passed with each line. By default these meta objects will be stringified and will not be searchable, but will be displayed for informational purposes.

If this option is turned to true then meta objects will be parsed and will be searchable up to three levels deep. Any fields deeper than three levels will be stringified and cannot be searched.

WARNING When this option is true, your metadata objects across all types of log messages MUST have consistent types or log entries will be silently dropped!

timestamp

Optional
Default: Date.now()

A timestamp in ms, must be within one day otherwise it will be dropped and Date.now() will be used in its place.

Winston Transport

This module also provides a transport object, which can be added to winston using:

var winston = require('winston');
var options = {
    key: apikey,
    hostname: myHostname,
    ip: ipAddress,
    mac: macAddress,
    app: appName
};

// Defaults to false, when true ensures meta object will be searchable
options.index_meta = true;

// Only add this line in order to track exceptions
options.handleExceptions = true;

winston.add(winston.transports.Logdna, options);

License

MIT © LogDNA

Happy Logging!

About

Node.js library for logging to LogDNA

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • JavaScript 100.0%