Log

Introduced in 1.0.0

Stability: 2 - Stable

const Log = require('kado/lib/Log')

This library provides logging abstraction to use different log transports for system level log messages.

Class: Log

Log extends ConnectEngine see ConnectEngine for engine management and more.

This is the log multiplexer to hold engines such as the LogEngine.

It only exposes ConnectEngine methods.

Class: LogEngine

Log extends Connect see Connect for more engine management and more.

static LogEngine.appendFile(path, data)

static LogEngine.tailFile(path, lineCount, options)

static LogEngine.getInstance()

LogEngine._read ()

Underlying stream read method for Stream.readable.

Internal Use

LogEngine.getDate(now)

Internal Use

LogEngine.message (level, msg, opts)

Pushes the newly formed message into the stream.

Internal Use

LogEngine.error (msg, opts)

Makes use of the Log.message method to send the log message.

LogEngine.warning (msg, opts)

Makes use of the Log.message method to send the log message.

LogEngine.info (msg, opts)

Makes use of the Log.message method to send the log message.

LogEngine.verbose (msg, opts)

Makes use of the Log.message method to send the log message.

LogEngine.debug (msg, opts)

Makes use of the Log.message method to send the log message.

LogEngine.extra (msg, opts)

Makes use of the Log.message method to send the log message.

LogEngine.dump (msg)

Makes use of the Log.message method to send the log message.

This method does not wrap the message with any status information.

LogEngine.constructor()

Class LogRelayUDP extends Stream.Writable

Relay log messages from any LogEngine using UDP.

Example Usage

// add our logger
const log = Log.LogEngine.getInstance({ name: pkg.name })
const logRelay = new Log.LogRelayUDP()
log.pipe(logRelay)
app.log.addEngine('console', log)

Example Log Receiver (this is a standalone program)

'use strict'
const dgram = require('dgram')
const server = dgram.createSocket('udp4')
server.on('error', (err) => { console.log(err) })
server.on('message', (msg) => { process.stdout.write(msg) })
server.on('listening', () => { console.log('Ready for Log Messages') })
server.bind('5514')

Log messages are send on UDP over port 5514. They are plain text.

Please consider transport layer encryption or keeping messages on a layer 2 networks to avoid security concerns.

LogRelayUDP.constructor(options)

Available Options

Since LogRelayUDP is a Stream.Writable instance and LogEngine is a Stream.Readable instance. Use the log relay by piping the engine into the relay prior to passing the engine into the log multiplexer.

Example

log.pipe(new Log.LogRelayUDP({ host: 'some-machine' }))

Class FileByLine

Based on: https://github.com/nacholibre/node-readlines

Read a file by lines.

FileByLine.constructor(options)

Available Options

FileByLine.next()

Example Usage

const fd = new FileByLine(path, options)
let line; const lines = []
while ((line = fd.next())) lines.push(line)