Skip to content
/ logger Public

πŸš… Sonic low overhead Logger designed to be used in SlimIO

License

Notifications You must be signed in to change notification settings

SlimIO/logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8c23774 Β· May 27, 2020

History

40 Commits
Jul 10, 2019
Jul 10, 2019
Jul 9, 2019
Jul 9, 2019
Jul 9, 2019
Jul 9, 2019
May 27, 2020
Jul 9, 2019
Jul 9, 2019
May 13, 2020
Jul 9, 2019
Jul 12, 2019
May 13, 2020
Jul 10, 2019
May 27, 2020
Jul 12, 2019

Repository files navigation

Logger

version Maintenance MIT dep size Known Vulnerabilities Build Status

SlimIO Sonic Logger. Very simple logger designed to be used in SlimIO. This package is inspired by pino logger.

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slimio/logger
# or
$ yarn add @slimio/logger

Usage example

const log = new Logger(void 0, {
    title: "MY-LOG"
});
for (let id = 0; id < 10; ++id) {
    log.writeLine("hello world!");
}

// end and flush writestream.
await log.close();

API

constructor(fd?: string | number, options?: Logger.ConstructorOptions)

Create a new Logger. The default value of fd is process.stdout.fd.

Options is described by the following TypeScript interface:

interface ConstructorOptions {
    title?: string;
    local?: string;
}

writeLine(msg?: string): void

Write a new line in the write stream. If the msg is undefined or equal to Empty String, then we write \n in the WriteStream.

log.writeLine("hello");
log.writeLine(void 0);
log.writeLine("bye bye !");

It will produce the following stdout

[my-log] Jul 10, 2019, 3:24:25 PM - hello

[my-log] Jul 10, 2019, 3:24:25 PM - bye bye !

close(): Promise< void >

Close and flush the stream.

Dependencies

Name Refactoring Security Risk Usage
flatstr Minor Low Flattens the underlying C structures of a concatenated JavaScript string
sonic-boom Minor High Extremely fast utf8-only stream implementation to write to files and file descriptors.

License

MIT