记录节点的stdout和stderr [英] Logging stdout and stderr of node

查看:152
本文介绍了记录节点的stdout和stderr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用平均值的代码,并使用命令启动服务器。

I am using boiler plate code of mean.io and starting the server with command

node server.js

如何记录我的快速申请的标准和标准?

How do I log stdout and stderr of my express application?

以下是我的server.js

Following is my 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");

注意:这两个功能都会自动为您的输入添加新行。

Note: both of these functions automatically add new line to your input.

如果您不希望在输入内添加这些换行符,请执行此操作

If you don't want those newlines appended to your input, do this

process.stdout.write("I will goto the STDOUT")
process.stderr.write("I will goto the STDERR")

process.stdout process.stderr 流,所以你甚至可以管道流入他们。有关详细信息,请参见 Stream.js文档

Both process.stdout and process.stderr are streams, so you can even pipe a stream into them. See Node.js docs on streams for more info.

这篇关于记录节点的stdout和stderr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆