在 Debian 系統上,Node.js 應用程序的日志級別通常是通過應用程序本身的配置來設置的。大多數 Node.js 應用程序使用第三方日志庫,如 winston
、bunyan
或 morgan
等。這些庫通常允許您設置不同的日志級別,例如:error、warn、info、http(或 verbose)、debug 和 silly。
以下是一些常見日志庫的日志級別設置方法:
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' }),
],
});
const bunyan = require('bunyan');
const logger = bunyan.createLogger({
name: 'myApp',
level: 'info', // 設置日志級別
});
const morgan = require('morgan');
const express = require('express');
const app = express();
app.use(morgan('combined')); // 設置日志級別為 'combined'
在這些示例中,我們將日志級別設置為 ‘info’。您可以根據需要更改為其他級別,如 ‘error’、‘warn’ 等。
如果您使用的是自定義日志記錄實現,請查閱相關文檔以了解如何設置日志級別。