1.2.0 • Published 5 years ago

ts-logger-service v1.2.0

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

Logger

Simple library written in Typescript.

Installation

Use npm to install the package:

npm install ts-logger-service

The package has been tested with typescript 3.4.3.

Important Full support for different versions is not guaranteed.

Usage

Create and use logger

Use the Factory

Every logger is instantiated into LoggerFactory. LoggerFactory provide static method to create and get a Logger.

LoggerFactory.instanceLogger('foo', LoggerLevels.INFO, new ConsoleLoggerService());
const logger = LoggerFactory.getLogger('foo');
logger.info('logger info'); // printed
logger.error('logger error'); // not printed

In this example we create a new Logger named foo, set its level to INFO and provide his service that manage every single log (see LoggerService).

After created we get the Logger from LoggerFactory by its name and call methods info and error to print in console. Here the result

1555267406390

Use decorator

Work in progress...

Create custom LoggerService

It's possible create custom LoggerService to specify behaviour for the logger. We must extends the abstract class LoggerService

export class CustomLoggerService extends LoggerService {

    // Console print
	debug(message: string): void {
		console.debug(message);
	}
    // Send error to API
	error(message: string): void {	
        this.http.post('http://log-api.it', {
            level: 'error'
            message: message
        })
	}
    // Write info into file
	info(message: string): void {
		fs.appendfile('log.txt', message);
	}
    .
    .
    .
}

It's in working the possibility to split the message in some different part (example logName, message, Date) to provide a more flessibility to the LoggerService.

Documentation

See HERE

License

Licenza MIT (todo)

Add copyright

1.2.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago