Skip to content

bipboy/logger

Repository files navigation

Logger

Lightweight Typescript logger using part of the ReScript code with priority levels


ts rs license release

Abstraction over using console.log with priority levels

Installation

This module is distributed via github npm registry (GitHub Packages) which is bundled with node and should be installed as one of your project's dependencies. See more about work with Github Packages and installing a package:

npm install @bipboys/logger

Usage

Simple Usage (Default Logger)

You can use logger functions directly without creating an instance. By default, all log levels are enabled:

import {error, info, warn, debug, verbose, log, trace} from '@bipboys/logger';

error('test error');
info('test info');
verbose('test verbose');
warn('test warn');
log('test log');
debug('test debug');
trace('test trace');
-------------------------------
Priority - DEFAULT
-------------------------------
[ERROR] 52:02.40 default test error
[INFO] 52:02.40 default test info
[VERBOSE] 52:02.40 default test verbose
[WARN] 52:02.40 default test warn
[INFO] 52:02.40 default test log
[DEBUG] 52:02.40 default test debug
[TRACE] 52:02.41 default test trace

Creating Custom Logger Instances

You can create named logger instances for different parts of your application:

import {make, error, info, warn} from '@bipboys/logger';

// Create a logger with specific name and log level
const logger = make('MyApp', 'DEBUG');

// The logger instance contains name and level information
console.log(logger); // { name: 'MyApp', level: 'DEBUG' }

This is useful when you want to differentiate log output from different components in your application.

Priority Levels

The logger supports 6 priority levels from lowest to highest:

  1. VERBOSE - Most verbose output
  2. DEBUG - Debugging information
  3. INFO - General information
  4. WARN - Warning messages
  5. ERROR - Error messages
  6. TRACE - Tracing information

Only messages with priority equal to or higher than the configured level will be displayed.

Usage with TypeScript

TypeScript types are automatically generated from ReScript code. Import types from the generated file:

import type {logLevel, consoleLoggerType} from '@bipboys/logger';
import {make, error, info, warn} from '@bipboys/logger';

const logger: consoleLoggerType = make('MyApp', 'DEBUG');
error('test error');
info('test info');

See the example file for a complete usage example.

About

Lightweight Typescript logger using part of the ReScript code with priority levels

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published