我是靠谱客的博主 失眠学姐,这篇文章主要介绍nodejs的debug模块使用及pm2输出,现在分享给大家,希望可以做个参考。

1、debug模块使用示例

const debug = require('debug');

const APP_NAME = 'myapp';

class Logger
{
	constructor(prefix)
	{
		if (prefix)
		{
			this._debug = debug(`${APP_NAME}:${prefix}`);
			this._info = debug(`${APP_NAME}:INFO:${prefix}`);
			this._warn = debug(`${APP_NAME}:WARN:${prefix}`);
			this._error = debug(`${APP_NAME}:ERROR:${prefix}`);
		}
		else
		{
			this._debug = debug(APP_NAME);
			this._info = debug(`${APP_NAME}:INFO`);
			this._warn = debug(`${APP_NAME}:WARN`);
			this._error = debug(`${APP_NAME}:ERROR`);
		}

		/* eslint-disable no-console */
		this._debug.log = console.info.bind(console);
		this._info.log = console.info.bind(console);
		this._warn.log = console.warn.bind(console);
		this._error.log = console.error.bind(console);
		/* eslint-enable no-console */
	}

	get debug()
	{
		return this._debug;
	}

	get info()
	{
		return this._info;
	}

	get warn()
	{
		return this._warn;
	}

	get error()
	{
		return this._error;
	}
}

module.exports = Logger;

2、要输入日志,需要带上DEBUG=myapp:*

类似 DEBUG=myapp:* node server.js

3、通过pm2运行时,要在pm2中打印出日志,也必须

 DEBUG=myapp:* pm2 start server.js --watch

最后

以上就是失眠学姐最近收集整理的关于nodejs的debug模块使用及pm2输出的全部内容,更多相关nodejs内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部