@dimjs/logger
v2.0.2
Published
Simple, pretty and powerful logger for nodejs
Downloads
96
Readme
@dimjs/logger
Simple, pretty and powerful logger for nodejs
Setup
Initialize
import { logger } from '@dimjs/logger';
logger.debug('hello', 'context');
And customized adapter with builtin sentry
import {
createLogger,
SentryAdapter,
SentryFormatStrategy,
} from '@dimjs/logger';
const logger = createLogger({
logLevel: LogLevel.Warn,
adapter: new SentryAdapter({
formatStrategy: new SentryFormatStrategy(),
}),
});
logger.debug('hello', 'context');
And customized adapters
// customize custom adapter
export class CustomAdapter<T> implements LogAdapter<T> {
isLoggable(priority: LogLevel, context?: string | undefined): boolean {
throw new Error('Method not implemented.');
}
config(config?: LogAdapterConfig | undefined): LogAdapter {
throw new Error('Method not implemented.');
}
print(priority: LogLevel, context: string, message: T, trace?: any): void {
throw new Error('Method not implemented.');
}
}
// customize custom format strategy for `CustomAdapter`
export class CustomFormatStrategy<T> implements FormatStrategy<T> {
print(priority: LogLevel, context: string, message: T, trace?: any): void {
throw new Error('Method not implemented.');
}
}
// create new logger
const logger = createLogger({
logLevel: LogLevel.Warn,
adapter: new SentryAdapter({
formatStrategy: new SentryFormatStrategy(),
}),
});
// attach new adapter
logger.addLogAdapter(
new SentryAdapter({
formatStrategy: new SentryFormatStrategy(),
})
);
logger.debug('print multi messages', 'demo');