1.5.6 • Published 10 days ago

@dimjs/logger v1.5.6

Weekly downloads
-
License
MIT
Repository
-
Last release
10 days ago

@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');
1.5.6

10 days ago

1.5.4

2 months ago

1.5.3

3 months ago

1.5.0

4 months ago

1.4.8

5 months ago

1.4.6

5 months ago

1.4.5

5 months ago

1.4.3

6 months ago

1.4.2

6 months ago

1.3.10

9 months ago

1.3.8

10 months ago

1.3.11

9 months ago

1.3.7

11 months ago

1.3.4

11 months ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.41

1 year ago

1.2.42

1 year ago

1.2.40

1 year ago

1.2.39

1 year ago

1.2.37

1 year ago

1.2.36

1 year ago

1.2.33

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago