2.2.3 • Published 5 years ago

@cactus-technologies/logger v2.2.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

@cactus-technologies/logger

version npm

Customized Pino Logger for Cactus projects


Table of contents

Installation

npm install @cactus-technologies/logger

Usage

const logger = require('@cactus-technologies/logger')
const log = logger('demo')
log.info('hello world')
{
    "level": 30,
    "time": 0000000,
    "msg": "hello world",
    "pid": 5218,
    "hostname": "demo-host",
    "name": "demo",
    "v": 1
}
log.error('this is at error level')
{
    "level": 50,
    "time": 0000000,
    "msg": "this is at error level",
    "pid": 000,
    "hostname": "demo-host",
    "name": "demo",
    "v": 1
}

All arguments supplied after message are serialized and interpolated according to any supplied printf-style placeholders.

log.info('the answer is %d', 42)
{
    "level": 30,
    "time": 0000000,
    "msg": "the answer is 42",
    "pid": 000,
    "hostname": "demo-host",
    "name": "demo",
    "v": 1
}

An object can optionally be supplied as the first parameter. Each enumerable key and value of the mergingObject is copied in to the JSON log line.

log.info({ a: { b: 'c' } }, 'Attachment')
{
    "level": 30,
    "time": 0000000,
    "msg": "Nested Attachment",
    "pid": 000,
    "hostname": "demo-host",
    "name": "demo",
    "a": { "b": "c" },
    "v": 1
}

Errors get Serialized

log.error(new Error('an error'))
{"level":50,"time":0000000,"msg":"an error","pid":000,"hostname":"demo-host","name":"demo",
 "err":{"message":"an error","name":"Error",
"stack":"Error: an error
    at Object.<anonymous> (/Users/mechanicalhuman/Active/cactus/utils/packages/logger/example.js:12:11)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:279:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)"},"v":1}

The logger.child method allows for the creation of stateful loggers, where key-value pairs can be pinned to a logger causing them to be output on every log line.

const child = log.child({ extra: 'property' })
child.info('hello child!')
{
    "level": 30,
    "time": 0000000,
    "msg": "hello child!",
    "pid": 000,
    "hostname": "demo-host",
    "name": "demo",
    "extra": "property",
    "v": 1
}

API

Maintainers

Changelog

Find the CHANGELOG here, generated using Conventional Commits.

License

MIT © Cactus Technologies LLC

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago