2 var streams = require('../streams')
3 , layouts = require('../layouts')
4 , path = require('path')
9 //close open files on process exit.
10 process.on('exit', function() {
11 openFiles.forEach(function (file) {
17 * File appender that rolls files according to a date pattern.
18 * @filename base filename.
19 * @pattern the format that will be added to the end of filename when rolling,
20 * also used to check when to roll files - defaults to '.yyyy-MM-dd'
21 * @layout layout function for log messages - defaults to basicLayout
22 * @timezoneOffset optional timezone offset in minutes - defaults to system local
24 function appender(filename, pattern, alwaysIncludePattern, layout, timezoneOffset) {
25 layout = layout || layouts.basicLayout;
27 var logFile = new streams.DateRollingFileStream(
30 { alwaysIncludePattern: alwaysIncludePattern }
32 openFiles.push(logFile);
34 return function(logEvent) {
35 logFile.write(layout(logEvent, timezoneOffset) + eol, "utf8");
40 function configure(config, options) {
44 layout = layouts.layout(config.layout.type, config.layout);
47 if (!config.alwaysIncludePattern) {
48 config.alwaysIncludePattern = false;
51 if (options && options.cwd && !config.absolute) {
52 config.filename = path.join(options.cwd, config.filename);
58 config.alwaysIncludePattern,
64 function shutdown(cb) {
67 var complete = function(err) {
70 if (completed >= openFiles.length) {
74 if (!openFiles.length) {
77 openFiles.forEach(function(file) {
78 if (!file.write(eol, "utf-8")) {
79 file.once('drain', function() {
88 exports.appender = appender;
89 exports.configure = configure;
90 exports.shutdown = shutdown;