typescript-ezlog
TypeScript icon, indicating that this package has built-in type declarations

0.5.6 • Public • Published

typescript-ezlog

Easy TypeScript library for logging in Nodejs.

Not tested yet!

  • Easy to integrate in Typescript projects
  • Easy to create custom loggers by using generalization
  • Easy to save logs to file
  • Set loglevel with envoirment variables
  • Set tag for file to find dedicated code
  • Fucking colorful

Installation

npm install --save typescript-ezlog

Requires typescript 2.7.1 (tested).

Usage

import { Logger } from 'typescript-ezlog';

const log: Logger = new Logger('tag');

log.err(new Error('error'));
log.warn('warning');
log.info('info');
log.deb('deb');

FileLogger

import { FileLogger } from 'typescript-ezlog';

const log: FileLogger = new FileLogger('tag');

log.err(new Error('this goes to console and error.log file'));
log.warn('this goes to console and verbose.log file');
log.info('this goes to console and verbose.log file');
log.deb('this goes to console and verbose.log file');

Custom

import { Logger, Level } from 'typescript-ezlog';

class CustomLogger extends Logger { 

    protected log(level: Level, data: string) { 
        //logs to console with color
        this.logToConsole(level, data);
        //do whatever you want
    }

    protected getTimestamp(): string { 
        //return preferred timestamp string
        return '';
    }

    protected transform(level: Level, data: any[]): string { 
        //applies tag, timestamp and builds a string
        return this.transform(level, data);
    }

}

Package Sidebar

Install

npm i typescript-ezlog

Weekly Downloads

14

Version

0.5.6

License

ISC

Unpacked Size

13 kB

Total Files

18

Last publish

Collaborators

  • lennart-zebandt