From 5ed50d545fd5aa6a44f3c5df2940cfd521a8f71b Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 15 Jun 2017 08:04:40 +1000 Subject: [PATCH] chore(examples): updated file logging example for 2.x --- examples/log-to-files.js | 45 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/examples/log-to-files.js b/examples/log-to-files.js index 6f140da..c30ccc5 100644 --- a/examples/log-to-files.js +++ b/examples/log-to-files.js @@ -1,36 +1,37 @@ -"use strict"; -var path = require('path') -, log4js = require('../lib/log4js'); +const log4js = require('../lib/log4js'); log4js.configure( { - appenders: [ - { - type: "file", - filename: "important-things.log", - maxLogSize: 10*1024*1024, // = 10Mb + appenders: { + file: { + type: 'file', + filename: 'important-things.log', + maxLogSize: 10 * 1024 * 1024, // = 10Mb numBackups: 5, // keep five backup files compress: true, // compress the backups encoding: 'utf-8', - mode: parseInt('0640', 8), + mode: 0o0640, flags: 'w+' }, - { - type: "dateFile", - filename: "more-important-things.log", - pattern: "yyyy-MM-dd-hh", + dateFile: { + type: 'dateFile', + filename: 'more-important-things.log', + pattern: 'yyyy-MM-dd-hh', compress: true }, - { - type: "stdout" + out: { + type: 'stdout' } - ] + }, + categories: { + default: { appenders: ['file', 'dateFile', 'out'], level: 'trace' } + } } ); -var logger = log4js.getLogger('things'); -logger.debug("This little thing went to market"); -logger.info("This little thing stayed at home"); -logger.error("This little thing had roast beef"); -logger.fatal("This little thing had none"); -logger.trace("and this little thing went wee, wee, wee, all the way home."); +const logger = log4js.getLogger('things'); +logger.debug('This little thing went to market'); +logger.info('This little thing stayed at home'); +logger.error('This little thing had roast beef'); +logger.fatal('This little thing had none'); +logger.trace('and this little thing went wee, wee, wee, all the way home.');