摩根与温斯顿一起使用的等级是多少?

时间:2017-03-25 09:45:24

标签: node.js express winston morgan

我目前正在学习登录nodejs的上下文。目前我的设置使用morgan作为快速中间件和winston作为我的日志记录。我的问题是摩根使用什么级别的日志记录?到目前为止这是我的appjs。我正在试图决定如何分割我的日志。

import bodyParser from "body-parser";
import express from "express";
import helmet from "helmet";
import morgan from "morgan";
import path from "path";
import { logger, stream } from "./utils/logger";
import es from "./esClient";

const app = express();

app.use(helmet());
app.use(morgan("combined", { stream }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

export default app;

这是我导入的记录器文件

import winston from "winston";
import path from "path";

winston.emitErrs = true;

const logger = new winston.Logger({
  transports: [
    new winston.transports.File({
      level: "info",
      name: "info",
      filename: path.join(__dirname,"..","..","logs/access.log"),
      json: true,
      maxsize: 5242880, //5MB
      maxFiles: 5,
      colorize: true
    }),
    new winston.transports.File({
      level: "verbose",
      name: "elasticsearch",
      filename: path.join(__dirname,"..","..","logs/elasticsearch.log"),
      json: true,
      maxsize: 5242880, //5MB
      maxFiles: 5,
      colorize: true
    }),
    new winston.transports.File({
      level: "error",
      name: "error",
      filename: path.join(__dirname,"..","..","logs/errors.log"),
      json: true,
      maxsize: 5242880, //5MB
      maxFiles: 5,
      colorize: true
    }),
    new winston.transports.Console({
      colorize: true,
      level: "warning"
    })
  ]
});

const stream = {
  write: function(message, encoding){
    logger.info(message);
  }
};

export { logger, stream };

编辑:为了澄清,我不希望我的http请求日志记录到我的数据库日志中。有没有办法做到这一点?

0 个答案:

没有答案