0.4.9 • Published 6 months ago

@vladmandic/pilogger v0.4.9

Weekly downloads
275
License
MIT
Repository
github
Last release
6 months ago

PiLogger: Simple Logger for NodeJS

Why

Because out of all of the existing modules, I couldn't find one that does what I needed and doesn't carry large number of unnecessary dependencies. There are far more complex loggers available, but sometimes all you need is simplicity with specific feature-set.
This module is written in pure ES6 with minimal dependencies.

Features

  • Extremely lightweight
  • Color coding of different log levels for console output
  • Support for console and file logging
  • Prefix messages with timestamp
  • Maintening configurable ring buffer of past messages
  • Automatic expansion of object parameters
  • Automatic concating of multiple parameters
  • All logging functions are asynchronous for non-blocking operations

Configuration

Configuration is optional.
If not configured, logging will be to console only and with default format
Configuring inspect options controls how object output is handled

const log = require('pilogger');
const options = {
  options.dateFormat: 'YYYY-MM-DD HH:mm:ss',
  ringLength: 100,
  logFile: './application.log',
  accessFile: './accesss.log',
  clientFile: './client.log',
  inspect: {
    showHidden: true,
    depth: 5,
    colors: true,
    showProxy: true,
    maxArrayLength: 1024,
    maxStringLength: 10240,
    breakLength: 200,
    compact: 64,
    sorted: false,
    getters: true,
  }
}
log.configure(options);

Usage

Messages that are printed to console only, useful for debugging

  log.print(...msg);

Messages that are mirrored to console and logFile (if set), each one prefixed and color coded

  log.blank(...msg);
  log.data(...msg);
  log.state(...msg);
  log.info(...msg);
  log.warn(...msg);
  log.error(...msg);

Example output (note that markdown rules strip colored output):

  2020-08-08 10:36:55 INFO:  piscan version 0.0.1
  2020-08-08 10:36:55 INFO:  User: root Platform: linux Arch: x64 Node: v14.4.0
  2020-08-08 10:36:55 STATE: Running as root with full capabilities
  2020-08-08 10:37:08 DATA:  host: pi ip: 192.168.0.100 time: 12,210
  2020-08-08 10:37:10 DATA:  mac: DC:A6:32:1B:74:D5 vendor: Raspberry Pi os: Linux 5.4
  2020-08-08 10:37:12 DATA:  ports: 22,139,445,514,873

Messages that are mirrored to console and logFile (if set), each one prefixed and color coded and with time measurement

  const t0 = process.hrtime.bigint();
  // do your stuff here
  log.timed(t0, ...msg);

Example output:

  2020-08-08 10:39:59 TIMED:  1,004 ms Test function execution

Messages that are output to accessFile (if set) only
Useful for detailed application access log that you don't want printed to console

  log.access(...msg);

Messages that are output to clientFile (if set) only
Useful for logging of any other messages that you don't want printed to console

  log.client(...msg);

Access to history ring buffer.
obj.time is message timestamp, obj.tag is message type (info, state, data, warn, error), obj.msg is parsed & concatened message string

  for (const line in log.ring) {
    console.log(log.ring[line].time, log.ring[line].tag), log.ring[line].msg);
  }
0.4.9

6 months ago

0.4.8

1 year ago

0.4.7

1 year ago

0.4.6

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.1

2 years ago

0.4.2

2 years ago

0.3.5

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.3

4 years ago

0.2.4

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.8

4 years ago

0.1.9

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago