diff --git a/examples/example.js b/examples/example.js index d304cc4..8879a23 100644 --- a/examples/example.js +++ b/examples/example.js @@ -1,3 +1,4 @@ +"use strict"; var log4js = require('../lib/log4js'); //log the cheese logger messages to a file, and the console ones as well. log4js.configure({ @@ -55,6 +56,3 @@ anotherLogger.debug("Just checking"); //will also go to console, since that's configured for all categories var pantsLog = log4js.getLogger('pants'); pantsLog.debug("Something for pants"); - - - diff --git a/examples/fromreadme.js b/examples/fromreadme.js index 71b399a..8d837f4 100644 --- a/examples/fromreadme.js +++ b/examples/fromreadme.js @@ -1,5 +1,5 @@ //remember to change the require to just 'log4js' if you've npm install'ed it -var log4js = require('./lib/log4js'); +var log4js = require('../lib/log4js'); //by default the console appender is loaded //log4js.loadAppender('console'); //you'd only need to add the console appender if you diff --git a/examples/log-to-files.js b/examples/log-to-files.js new file mode 100644 index 0000000..6f140da --- /dev/null +++ b/examples/log-to-files.js @@ -0,0 +1,36 @@ +"use strict"; +var path = require('path') +, log4js = require('../lib/log4js'); + +log4js.configure( + { + appenders: [ + { + 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), + flags: 'w+' + }, + { + type: "dateFile", + filename: "more-important-things.log", + pattern: "yyyy-MM-dd-hh", + compress: true + }, + { + type: "stdout" + } + ] + } +); + +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."); diff --git a/lib/appenders/dateFile.js b/lib/appenders/dateFile.js index 86635d7..5451d15 100644 --- a/lib/appenders/dateFile.js +++ b/lib/appenders/dateFile.js @@ -21,13 +21,13 @@ process.on('exit', function() { * @layout layout function for log messages - defaults to basicLayout * @timezoneOffset optional timezone offset in minutes - defaults to system local */ -function appender(filename, pattern, alwaysIncludePattern, layout, timezoneOffset) { +function appender(filename, pattern, layout, options, timezoneOffset) { layout = layout || layouts.basicLayout; var logFile = new streams.DateRollingFileStream( filename, pattern, - { alwaysIncludePattern: alwaysIncludePattern } + options ); openFiles.push(logFile); @@ -55,8 +55,8 @@ function configure(config, options) { return appender( config.filename, config.pattern, - config.alwaysIncludePattern, layout, + config, config.timezoneOffset ); } diff --git a/lib/appenders/file.js b/lib/appenders/file.js index 2893091..bbb40dd 100644 --- a/lib/appenders/file.js +++ b/lib/appenders/file.js @@ -47,7 +47,7 @@ function fileAppender (file, layout, logSize, numBackups, options, timezoneOffse //there has to be at least one backup if logSize has been specified numBackups = numBackups === 0 ? 1 : numBackups; - debug("Creating file appender (", file, ", ", logSize, ", ", numBackups, ", ", options, ")"); + debug("Creating file appender (", file, ", ", logSize, ", ", numBackups, ", ", options, ", ", timezoneOffset, ")"); var writer = openTheStream(file, logSize, numBackups, options); // push file to the stack of open handlers @@ -88,8 +88,8 @@ function configure(config, options) { layout, config.maxLogSize, config.backups, - config.timezoneOffset, - config + config, + config.timezoneOffset ); }