A simple but highly customizable TypeScript logger.
- Bundled with rollup in es5 format.
- Configure once - if used in libraries you consume, the main app can configure the logger globally
- Works well with other frameworks.
- Angular 5 Apps and AOT compilation is supported.
Install via NPM: npm i --save @elderbyte/ts-logger
import {LoggerFactory} from '@elderbyte/ts-logger';
class MyClass {
private logger = LoggerFactory.getLogger('MyClass');
public myMethod(): void {
this.logger.info('You invoked myMethod!');
}
}
Will result in a log like:
2018-01-11T14:28:49.401Z [DEBUG] MyClass You invoked myMethod!
Browser which support coloring will also have different colors depending on the log level.
Configuration is provided with default values to support out of the box working logging expirience.
Each LoggerFactory
instance can be configured independently. There is however a global, static default instance and its recommended to use this accross all your projects and libraries. This will allow to configure the logger on a central place (such as your main app).
You can configure the max log level, custom appenders and message formatter. All of these are optional.
LoggerFactory.getDefaultConfiguration()
.withMaxLevel(LogLevel.Trace) // Defaults to Info
.withAppender(new ConsoleLogAppender()) // Same as default
.withFormatter(new SimpleMessageFormatter()) // Same as default