在Ubuntu上监控Node.js实时日志,可采用以下方法:
tail -f:实时查看日志文件,如 tail -f /path/to/app.log。watch:定期执行命令监控文件变化,如 watch -n 2 tail -f /path/to/app.log。const winston = require('winston'); const logger = winston.createLogger({ transports: [new winston.transports.Console(), new winston.transports.File({ filename: 'app.log' })] }); logger.info('实时日志信息'); ```。 pm2 start app.js + pm2 logs。根据需求选择工具,开发环境可优先用nodemon或PM2,生产环境推荐Elasticsearch+Kibana或Log.io。