8000 GitHub - Pingid/lickle-log at 0.0.1
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Pingid/lickle-log

Repository files navigation

A little logger

A tiny structured logging utility that includes, customizable transports, metadata.

Build Status Build Size Version Downloads

Install

Install the @lickle/log library using your preferred package manager:

npm install @lickle/log

Usage

Default Logger

The default logger uses a console-based structured logger transport. Here's how to use it:

import log from '@lickle/log'

log.info`initialised`
// Output: { level: 'info', time: '...', msg: 'initialised' }

log.info({ userId: '...' })`user authenticated`
// Output: { level: 'info', time: '...', msg: 'user authenticated', meta: { userId: '...' } }

log.info('started tast')
// Output: { level: 'info', time: '...', msg: 'started tast' }

log.error(new Error('task failed'))
// Output: { level: 'error', time: '...', msg: 'task failed', meta: { stack: '...' } }

Adding Metadata

You can add metadata to the logger using the log.meta method. Metadata fields are merged by default. To replace existing metadata, pass true as the second argument log.meta({ ... }, true).

import log from '@lickle/log'

log.meta({ requestId: '123' })

log.info`start`
// Output: { level: 'info', time: '...', msg: 'start', meta: { requestId: '123' } }

Configuration

Customizing the Transport

Customize the transport function for the top-level logger as shown below:

import log from '@lickle/log'

log.configure({
  transport: (lg) => console[lg.level](`[${lg.time}] ${lg.msg}\n${JSON.stringify(lg.meta)}`),
})

Creating a New Logger Instance

You can create a new logger instance with custom configurations:

import { create } from '@lickle/log'

const logger = create({
  meta: {},
  transport: (lg) => console[lg.level](`[${lg.time}] ${lg.msg}\n${JSON.stringify(lg.meta)}`),
})

License

This project is licensed under the MIT License.

MIT © Dan Beaven

About

A tiny structured logging utility that includes, customizable transports, metadata.

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0