nestjs-log
TypeScript icon, indicating that this package has built-in type declarations

2.0.6 • Public • Published

nestjs-log

Build Status Coverage Status npm

A log can be used as nestjs system logger and application logger. Logs can be rotated based on date('YYYY-MM-DD-HH'), size limit(1G), and old logs will be removed after 14 days. This module wrapps winston.

Usage

npm install nestjs-log

example as application logger

const log = getLog(TAG) // TAG is a label usually as same as the class

log.verbose(`msg`)
log.debug(`msg`)
log.info(`msg`)
log.warn(`msg`)
log.error(`msg`)

// also support splat
log.info('msg', any1, any2, any3)
log.info(obj)

example as nestjs system logger

const app = await NestFactory.create(AppModule, {
    logger: getLog('system').loggerService
  });

environment variables

log level: 
  process.env.LOG_LEVEL ?? 'info'

log dir: 
  process.env.LOG_DIR ?? './log'

log date pattern: 
  process.env.LOG_DATE_PATTERN ?? 'YYYY-MM-DD-HH'

log file name:
  process.env.LOG_FILE_NAME ?? 'app'

log file max size: 
  process.env.LOG_MAX_SIZE ?? '1024m'
  Maximum size of the file after which it will rotate. This can be a number of bytes, or units of kb, mb, and gb. If using the units, add 'k', 'm', or 'g' as the suffix. The units need to directly follow the number.

log file rotation policy: 
  process.env.LOG_MAX_FILES ?? '14d' 
  Maximum number of logs to keep. This can be a number of files or number of days. If using days, add 'd' as the suffix.

log to console:
  set process.env.NODE_ENV to 'dev'

Readme

Keywords

Package Sidebar

Install

npm i nestjs-log

Weekly Downloads

1

Version

2.0.6

License

MIT

Unpacked Size

232 kB

Total Files

6

Last publish

Collaborators

  • bibber