egg-conosle,找到 Express 上 Morgan 的体验

694 阅读1分钟

NPM version build status Test coverage David deps Known Vulnerabilities npm download

中文版

This plug works like morgan, prints all request & result both to console and local file.

Generally, it prints [$userId/$ip/$traceId/${cost}ms $method $url] $status. If there's an error, it will print the error attached. If the config.consoleLevel is set to debug, it will prints the request body as json format attached.

This plugin needs egg-logger which is a built-in plugin of egg.js. It bases on ctx.logger, so the options of it will also impact this plugin.

Install

NPM

$ npm i egg-console --save

yarn

$ yarn add egg-console

Usage

// {app_root}/config/plugin.js
exports.console = {
  enable: true,
  package: 'egg-console',
};

Configuration

// {app_root}/config/config.default.js
exports.console = {
  consoleLevel: 'info',
  success: 'green',
  error: 'red',
  debug: 'gray',
};

If the consoleLevel is not given, the config.logger.consoleLevel will work.

see config/config.default.js for more detail.

License

MIT