2.0.2 • Published 9 months ago

@dimjs/logger v2.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months 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');
2.0.2

9 months ago

2.0.0-next.2

11 months ago

2.0.0-next.1

1 year ago

2.0.1

11 months ago

2.0.0

11 months ago

1.5.6

1 year ago

1.5.4

1 year ago

1.5.3

1 year ago

1.5.0

1 year ago

1.4.8

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.3.10

2 years ago

1.3.8

2 years ago

1.3.11

2 years ago

1.3.7

2 years ago

1.3.4

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.41

2 years ago

1.2.42

2 years ago

1.2.40

2 years ago

1.2.39

2 years ago

1.2.37

2 years ago

1.2.36

2 years ago

1.2.33

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago