loglin

loglin

Usage no npm install needed!

<script type="module">
  import loglin from 'https://cdn.skypack.dev/loglin';
</script>

README

loglin

Super fast, lightweight and extensible logger for Node.js

npm version npm downloads

Why loglin?

⚡️  Lightning Fast Logging
🛠️  Rich Features
🔌  Pluggable Reporters
🍃  Lightweight
👶  Easy To Use
🔑  Fully Typed

Installation

1. Core

# pnpm
pnpm install loglin

# npm
npm i loglin

# yarn
yarn add loglin

2. Minimum one reporter (e.g. reporter-console)

See all Available Reporters

# pnpm
pnpm install @loglin/reporter-console

# npm
npm i @loglin/reporter-console

# yarn
yarn add @loglin/reporter-console

Getting Started

// With imports
import { createLogger } from 'loglin'
import { consoleReporter } from '@loglin/reporter-console'

// With require
const { createLogger } = require('loglin')
const { consoleReporter } = require('@loglin/reporter-console')

// Create logger instance
const logger = createLogger({
    reporters: [
        consoleReporter()
    ]
})

// Use log methods
logger.success('Successfully built')
logger.fatal(new Error('Something bad happend'))
logger.info('Some info', { foo: 'bar' })
// ...

Log Methods

  • logger.fatal()
  • logger.error()
  • logger.warn()
  • logger.log()
  • logger.info()
  • logger.success()
  • logger.debug()

Each log method can receive the actual log data as the first argument and optional meta data as the second argument. The meta data is for providing some additional information which you can check/print/process in your reporter's log function.

Example:

logger.info('Received info', { name: 'Foo Bar' })

Log Levels

  • LogLevel.Fatal
  • LogLevel.Error
  • LogLevel.Warn
  • LogLevel.Log
  • LogLevel.Info
  • LogLevel.Success
  • LogLevel.Debug

Available Reporters

Available Filters

isMinimumLevel(level)

level

  • Type: LogLevel

Minimum level where the logger should execute the log function. Can be any of the Log Levels.

API

createLogger(options)

reporters

  • Type: Reporter[]
  • Default: []

Specify the reporters the logger should use. Minimum one is required.

filters

  • Type: Filter[]
  • Default: []

Global filters for filtering out logs of all reporters. Perfect for filtering logs based on the log level.
See Available Filters.

License

MIT