@midwayjs/logger
[![Package Quality](http://npm.packagequality.com/shield/@midwayjs/logger.svg)](http://packagequality.com/#?package=@midwayjs/logger) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)
Last updated 5 years ago by czy88840616 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @midwayjs/logger 
SYNC missed versions from official npm registry.

@midwayjs/logger

PRs Welcome

@midwayjs/logger is a log module extended based on winston, which is suitable for log output under a single process, and supports multiple formats and customizations.

Install

$ npm install @midwayjs/logger --save

Create Logger

import { loggers } from '@midwayjs/logger';

const logger = loggers.createLogger('logger', {
  // some logger options
})

Create console, file and error Logger.(default logger, include console, file and error 3 transports)

const logger = loggers.createLogger('logger', {
  dir: '...',
  fileLogName: 'app.log',
  errorLogName: 'error.log',
})

Create console logger(just disable file and error transports)

const logger = loggers.createLogger('consoleLogger', {
  enableFile: false,
  enableError: false,
})

Logger Output Method

logger.debug('debug info');
logger.info('启动耗时 %d ms', Date.now() - start);
logger.warn('warning!');
logger.error(new Error('my error'));

Logger Level

log level is divided into the following categories, and the log level decreases sequentially (the larger the number, the lower the level):

const levels = {
  none: 0,
  error: 1,
  trace: 2,
  warn: 3,
  info: 4,
  verbose: 5,
  debug: 6,
  silly: 7,
  all: 8,
}

Set level for all transports

const logger = loggers.createLogger('logger', {
  dir: '...',
  level: 'warn',
  fileLogName: 'app.log',
  errorLogName: 'error.log',
});

// not output
logger.debug('debug info');

// not output
logger.info('debug info');

Format

Change file and error logger format.

const logger = loggers.createLogger('logger', {
  dir: '...',
  level: 'warn',
  fileLogName: 'app.log',
  errorLogName: 'error.log',
  format: info => {
    return `${info.timestamp} ${info.message}`;
  }
});

info is a winston metadata we called 'MidwayTransformableInfo' and include some default value;

Logger Options

find more options in interface.

License

MIT

Current Tags

  • 3.0.0-alpha.42                                ...           alinode-stable (5 years ago)
  • 3.0.0-alpha.43                                ...           alpha (5 years ago)
  • 3.0.0-beta.13                                ...           beta (4 years ago)
  • 2.17.0                                ...           latest (4 years ago)

67 Versions

  • 2.17.0                                ...           4 years ago
  • 2.16.3                                ...           4 years ago
  • 2.16.2                                ...           4 years ago
  • 2.16.1                                ...           4 years ago
  • 2.16.0                                ...           4 years ago
  • 2.15.0                                ...           4 years ago
  • 2.14.2                                ...           4 years ago
  • 2.14.1                                ...           4 years ago
  • 2.14.0                                ...           4 years ago
  • 3.0.0-beta.13                                ...           4 years ago
  • 3.0.0-beta.12                                ...           4 years ago
  • 3.0.0-beta.11                                ...           4 years ago
  • 3.0.0-beta.10                                ...           4 years ago
  • 3.0.0-beta.9                                ...           4 years ago
  • 3.0.0-beta.8                                ...           4 years ago
  • 3.0.0-beta.7                                ...           4 years ago
  • 3.0.0-beta.6                                ...           4 years ago
  • 3.0.0-beta.5                                ...           4 years ago
  • 3.0.0-beta.4                                ...           4 years ago
  • 3.0.0-beta.3                                ...           4 years ago
  • 3.0.0-beta.2                                ...           4 years ago
  • 3.0.0-beta.1                                ...           4 years ago
  • 3.0.0-alpha.43                                ...           5 years ago
  • 3.0.0-alpha.42                                ...           5 years ago
  • 3.0.0-alpha.41                                ...           5 years ago
  • 3.0.0-alpha.28                                ...           5 years ago
  • 2.13.0                                ...           5 years ago
  • 2.11.4-beta.1                                ...           5 years ago
  • 2.11.4-beta.q                                ...           5 years ago
  • 3.0.0-alpha.6                                ...           5 years ago
  • 2.11.3                                ...           5 years ago
  • 2.11.2                                ...           5 years ago
  • 2.11.1                                ...           5 years ago
  • 2.11.0                                ...           5 years ago
  • 2.10.18                                ...           5 years ago
  • 2.10.15                                ...           5 years ago
  • 2.10.15-beta.1                                ...           5 years ago
  • 2.10.14                                ...           5 years ago
  • 2.10.13                                ...           5 years ago
  • 2.10.12                                ...           5 years ago
  • 2.10.11                                ...           5 years ago
  • 2.10.7                                ...           5 years ago
  • 2.10.6                                ...           5 years ago
  • 2.10.5                                ...           5 years ago
  • 2.10.0                                ...           5 years ago
  • 2.10.0-beta.4                                ...           5 years ago
  • 2.10.0-beta.3                                ...           5 years ago
  • 2.10.0-beta.2                                ...           5 years ago
  • 2.8.13                                ...           5 years ago
  • 2.8.11                                ...           5 years ago
  • 2.8.2                                ...           5 years ago
  • 2.8.0                                ...           5 years ago
  • 2.7.5                                ...           5 years ago
  • 2.7.0                                ...           5 years ago
  • 2.6.13                                ...           5 years ago
  • 2.6.10                                ...           5 years ago
  • 2.6.9                                ...           5 years ago
  • 2.6.8                                ...           5 years ago
  • 2.6.7                                ...           5 years ago
  • 2.6.6                                ...           5 years ago
  • 2.6.5                                ...           5 years ago
  • 2.6.4                                ...           5 years ago
  • 2.6.3                                ...           5 years ago
  • 2.6.2                                ...           5 years ago
  • 2.6.1                                ...           5 years ago
  • 2.6.0                                ...           5 years ago
  • 2.5.0                                ...           5 years ago
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |