@litert/logger
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

LiteRT/Logger

npm version License node GitHub issues GitHub Releases

A logs writer for LiteRT framework.

Features

  • [x] Log stack trace.
  • [x] Enable/Disable log levels.
  • [x] Custom levels.
  • [x] Custom formats.
  • [x] 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.

Readme

Keywords

Package Sidebar

Install

npm i @litert/logger

Weekly Downloads

72

Version

2.0.0

License

Apache-2.0

Unpacked Size

70 kB

Total Files

39

Last publish

Collaborators

  • fenying