在 Debian 系统上,Node.js 应用程序的日志级别通常是通过应用程序本身的配置来设置的。大多数 Node.js 应用程序使用第三方日志库,如 winston
、bunyan
或 morgan
等。这些库通常允许您设置不同的日志级别,例如:error、warn、info、http(或 verbose)、debug 和 silly。
以下是一些常见日志库的日志级别设置方法:
- Winston:
const winston = require('winston'); const logger = winston.createLogger({ level: 'info', // 设置日志级别 format: winston.format.json(), transports: [ new winston.transports.File({ filename: 'error.log', level: 'error' }), new winston.transports.File({ filename: 'combined.log' }), ], });
- Bunyan:
const bunyan = require('bunyan'); const logger = bunyan.createLogger({ name: 'myApp', level: 'info', // 设置日志级别 });
- Morgan:
const morgan = require('morgan'); const express = require('express'); const app = express(); app.use(morgan('combined')); // 设置日志级别为 'combined'
在这些示例中,我们将日志级别设置为 ‘info’。您可以根据需要更改为其他级别,如 ‘error’、‘warn’ 等。
如果您使用的是自定义日志记录实现,请查阅相关文档以了解如何设置日志级别。