added shutdown to datefile
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var streams = require('../streams')
|
var streams = require('../streams')
|
||||||
, layouts = require('../layouts')
|
, layouts = require('../layouts')
|
||||||
|
, async = require('async')
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
, os = require('os')
|
, os = require('os')
|
||||||
, eol = os.EOL || '\n'
|
, eol = os.EOL || '\n'
|
||||||
@@ -24,12 +25,12 @@ function appender(filename, pattern, alwaysIncludePattern, layout) {
|
|||||||
layout = layout || layouts.basicLayout;
|
layout = layout || layouts.basicLayout;
|
||||||
|
|
||||||
var logFile = new streams.DateRollingFileStream(
|
var logFile = new streams.DateRollingFileStream(
|
||||||
filename,
|
filename,
|
||||||
pattern,
|
pattern,
|
||||||
{ alwaysIncludePattern: alwaysIncludePattern }
|
{ alwaysIncludePattern: alwaysIncludePattern }
|
||||||
);
|
);
|
||||||
openFiles.push(logFile);
|
openFiles.push(logFile);
|
||||||
|
|
||||||
return function(logEvent) {
|
return function(logEvent) {
|
||||||
logFile.write(layout(logEvent) + eol, "utf8");
|
logFile.write(layout(logEvent) + eol, "utf8");
|
||||||
};
|
};
|
||||||
@@ -38,15 +39,15 @@ function appender(filename, pattern, alwaysIncludePattern, layout) {
|
|||||||
|
|
||||||
function configure(config, options) {
|
function configure(config, options) {
|
||||||
var layout;
|
var layout;
|
||||||
|
|
||||||
if (config.layout) {
|
if (config.layout) {
|
||||||
layout = layouts.layout(config.layout.type, config.layout);
|
layout = layouts.layout(config.layout.type, config.layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.alwaysIncludePattern) {
|
if (!config.alwaysIncludePattern) {
|
||||||
config.alwaysIncludePattern = false;
|
config.alwaysIncludePattern = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options && options.cwd && !config.absolute) {
|
if (options && options.cwd && !config.absolute) {
|
||||||
config.filename = path.join(options.cwd, config.filename);
|
config.filename = path.join(options.cwd, config.filename);
|
||||||
}
|
}
|
||||||
@@ -54,5 +55,18 @@ function configure(config, options) {
|
|||||||
return appender(config.filename, config.pattern, config.alwaysIncludePattern, layout);
|
return appender(config.filename, config.pattern, config.alwaysIncludePattern, layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shutdown(cb) {
|
||||||
|
async.forEach(openFiles, function(file, done) {
|
||||||
|
if (!file.write(eol, "utf-8")) {
|
||||||
|
file.once('drain', function() {
|
||||||
|
file.end(done);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
file.end(done);
|
||||||
|
}
|
||||||
|
}, cb);
|
||||||
|
}
|
||||||
|
|
||||||
exports.appender = appender;
|
exports.appender = appender;
|
||||||
exports.configure = configure;
|
exports.configure = configure;
|
||||||
|
exports.shutdown = shutdown;
|
||||||
|
|||||||
Reference in New Issue
Block a user