2.0.0 • Published 4 months ago

@litert/logger v2.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

LiteRT/Logger

npm version License node GitHub issues GitHub Releases

A logs writer for LiteRT framework.

Features

  • Log stack trace.
  • Enable/Disable log levels.
  • Custom levels.
  • Custom formats.
  • Custom output drivers.

Requirement

  • TypeScript v5.0.0 (or newer)
  • Node.js v18.0.0 (or newer)

Installation

Install by NPM:

npm i @litert/logger --save

Quick Start

Simple usage:

// The imported module is a LoggerFactory singleton object, so you can use it directly.
import LoggerFactory from "@litert/logger";

const logger = LoggerFactory.createLogger('Demo');

logger.info('Hello, world!');
logger.warning('Hello, world!');

// Now, just disable a level, and it will not be printed.
logger.setLevelOptions({ levels: ['error'], enabled: false });

logger.error('Hello, world! (WILL NOT BE PRINTED)');

// let's turn on the stack trace, print 2 lines of stack trace.
//
// without specifying levels, all levels will be affected.
logger.setLevelOptions({ traceDepth: 2 });

logger.notice('Hello, world!');

Use custom log formatter:

import LoggerFactory from "@litert/logger";

LoggerFactory.setLevelOptions({ enabled: true });

const logger = LoggerFactory.createLogger('Demo');

logger.setLevelOptions({
    formatter: function(log, subj, lv, dt, traces): string {

        if (traces?.length) {

            return `${new Date(dt).toISOString()} - ${subj} - ${lv} - ${log}

  ${traces.join('\n  ')}
`;
        }

        return `${new Date(dt).toISOString()} - ${subj} - ${lv} - ${log}`;
    }
});

logger.info('Hello, world!');
logger.warning('Hello, world!');

logger.setLevelOptions({ traceDepth: 2 });

logger.error('Hello, world!');

More Examples:

License

This library is published under Apache-2.0 license.

2.0.0

4 months ago

1.2.0

7 months ago

1.2.1

7 months ago

1.1.4

2 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago