企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
#### installation ~~~ npm install log4js ~~~ #### usage Minimalist version: ~~~ var log4js = require('log4js'); var logger = log4js.getLogger(); logger.level = 'debug'; logger.debug("Some debug messages"); ~~~ By default, log4js will not output any logs (so that it can safely be used in libraries). The level for the default category is set to OFF. To enable logs, set the level (as in the example). This will then output to stdout with the coloured layout (thanks to masylum), so for the above you would see: > [2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages See example.js for a full example, but here's a snippet (also in examples/fromreadme.js): ~~~ const log4js = require('log4js'); log4js.configure({ appenders: { cheese: { type: 'file', filename: 'cheese.log' } }, categories: { default: { appenders: ['cheese'], level: 'error' } } }); const logger = log4js.getLogger('cheese'); 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.'); Output (in cheese.log): ~~~ > [2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe! > [2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground for listeria. * * * * * https://www.npmjs.com/package/log4js