0.5.6 • Published 6 years ago

typescript-ezlog v0.5.6

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

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);
    }

}
0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago