我正在使用 mean.io 的样板代码并使用以下命令启动我的服务器:
node server.js
如何记录我的 Express 应用程序的 stdout
和 stderr
?
这是我的文件 server.js
:
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
passport = require('passport'),
logger = require('mean-logger');
/**
* Main application entry file.
* Please note that the order of loading is important.
*/
// Initializing system variables
var config = require('./server/config/config');
var db = mongoose.connect(config.db);
// Bootstrap Models, Dependencies, Routes and the app as an express app
var app = require('./server/config/system/bootstrap')(passport, db);
// Start the app by listening on <port>, optional hostname
app.listen(config.port, config.hostname);
console.log('Mean app started on port ' + config.port + ' (' + process.env.NODE_ENV + ')');
// Initializing logger
logger.init(app, passport, mongoose);
// Expose app
exports = module.exports = app;
最佳答案
这个怎么样?
console.log("I will goto the STDOUT");
console.error("I will goto the STDERR");
注意:这两个函数都会自动在您的输入中添加新行。
如果您不希望将这些换行符附加到您的输入中,请执行此操作
process.stdout.write("I will goto the STDOUT")
process.stderr.write("I will goto the STDERR")
process.stdout
和 process.stderr
都是流,因此您甚至可以通过管道将流导入它们。见 Node.js docs on streams了解更多信息。
关于node.js - 记录Node的stdout和stderr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23861917/