NodeJS Log 4 JS
Log 4 JSはJSのログ機能を実現しました. ロゴ4 Jに相当します
公式サイトから見ると、やはり全面的です.
次のような山があります
1コンソールログ
2 nodeJSのconsolie.log機能を置換する
3ファイル適応機能 ログファイルのサイズに応じて分割します.
4 STMP GELF HOME.io logly 似合います.
5 connect/express serverログ
6 異なるログレベルと異なるログの種類
Log 4 JS実装
公式サイトから見ると、やはり全面的です.
次のような山があります
1コンソールログ
2 nodeJSのconsolie.log機能を置換する
3ファイル適応機能 ログファイルのサイズに応じて分割します.
4 STMP GELF HOME.io logly 似合います.
5 connect/express serverログ
6 異なるログレベルと異なるログの種類
Log 4 JS実装
[root@localhost darion.yaphet]# npm install log4js
npm http GET https://registry.npmjs.org/log4js
npm http 200 https://registry.npmjs.org/log4js
npm http GET https://registry.npmjs.org/log4js/-/log4js-0.6.12.tgz
npm http 200 https://registry.npmjs.org/log4js/-/log4js-0.6.12.tgz
npm http GET https://registry.npmjs.org/async/0.1.15
npm http GET https://registry.npmjs.org/readable-stream
npm http GET https://registry.npmjs.org/semver
npm http 200 https://registry.npmjs.org/async/0.1.15
npm http GET https://registry.npmjs.org/async/-/async-0.1.15.tgz
npm http 200 https://registry.npmjs.org/readable-stream
npm http GET https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.26-4.tgz
npm http 200 https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.26-4.tgz
npm http 200 https://registry.npmjs.org/semver
npm http GET https://registry.npmjs.org/semver/-/semver-1.1.4.tgz
npm http 200 https://registry.npmjs.org/semver/-/semver-1.1.4.tgz
npm http 200 https://registry.npmjs.org/async/-/async-0.1.15.tgz
npm http GET https://registry.npmjs.org/isarray/0.0.1
npm http GET https://registry.npmjs.org/string_decoder
npm http GET https://registry.npmjs.org/core-util-is
npm http GET https://registry.npmjs.org/inherits
npm http 200 https://registry.npmjs.org/core-util-is
npm http GET https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz
npm http 200 https://registry.npmjs.org/inherits
npm http 200 https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz
npm http 200 https://registry.npmjs.org/string_decoder
npm http GET https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.25-1.tgz
npm http 200 https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.25-1.tgz
npm http 200 https://registry.npmjs.org/isarray/0.0.1
npm http GET https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz
npm http 200 https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz
[email protected] node_modules/log4js
├── [email protected]
├── [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected])
[root@localhost darion.yaphet]#
初歩使用~var log4js = require('log4js');
var logger = log4js.getLogger();
logger.debug("example 4 logging");
印刷結果は標準出力ストリーム~[email protected]:/home/darion.yaphet/test/node/log4js> node example.js 14-03-31 23:19
[2014-03-31 23:19:37.032] [DEBUG] [default] - example 4 logging
ちょっと意味のある例を見てください. ファイルにロゴを書くvar log4js = require('log4js');
//console log is loaded by default, so you won't normally need to do this
//log4js.loadAppender('console');
log4js.loadAppender('file');
//log4js.addAppender(log4js.appenders.console());
log4js.addAppender(log4js.appenders.file('logs/example.log'), 'cheese');
var logger = log4js.getLogger('cheese');
logger.setLevel('ERROR');
logger.trace('Entering cheese testing');
logger.debug('Got cheese.');
logger.info('Cheese is Gouda.');
logger.warn('Cheese is quite smelly.');
logger.error('Cheese is too ripe!');
logger.fatal('Cheese was breeding ground for listeria.');