2.1.1 • Published 2 years ago

@mocko/logger v2.1.1

Weekly downloads
18
License
ISC
Repository
github
Last release
2 years ago

Mocko Logger

This is the logging module used by Mocko.

Usage

With Mocko Logger, you can create logging templates that you'll use later to log structured messages. Here's an example:

import { LogColumn, Logger } from '@mocko/logger';
import * as colors from 'colors/safe';

const log = new Logger()
    .column(LogColumn.fixed('[mocko]').color(colors.blue))
    .column(LogColumn.timestamp().clf().color(colors.dim))
    .column(LogColumn.text().size(7).right().color(colors.gray))
    .column(LogColumn.text())
    .log;

log("info", "Hi there :)");
log("warning", "Lorem ipsum dolor sit amet");

This would produce:

Logs

Columns

Generic

All columns provide you with the .color modifier. You can pass a color function from any lib you use. Example:

import { LogColumn, Logger } from '@mocko/logger';
import * as colors from 'colors/safe';

const log = new Logger()
    .column(LogColumn.text().color(colors.magenta))
    .log;

log('This text is magenta :)');

Fixed

The fixed column is a piece of text that won't change. It doesn't require a new parameter from the user. Example:

import { LogColumn, Logger } from '@mocko/logger';
import * as colors from 'colors/safe';

const warn = new Logger()
    .column(LogColumn.fixed('WARN').color(colors.yellow))
    .column(LogColumn.text())
    .log;

warn('This is a warning');

Text

The text column requires a new parameter from the user and will apply its rules to it. A fixed size text will have padding added to the beggining or end of it deppending on the alignment (right/left). The default is left-aligned text.

Timestamp

The timestamp column prints the current time, it doesn't require a new parameter from the user. You can format it with .iso, .utc, .clf or .millis. The default is clf. Example:

import { LogColumn, Logger } from '@mocko/logger';
import * as colors from 'colors/safe';

const warn = new Logger()
    .column(LogColumn.timestamp().iso().color(colors.dim))
    .column(LogColumn.fixed('WARN').color(colors.yellow))
    .column(LogColumn.text())
    .log;

warn('This is a warning');
2.1.1

2 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago