Skip to content

Commit

Permalink
Add restart function for targets to support log rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Thompson committed Dec 3, 2015
1 parent 53e49a1 commit c8957c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Bristol.js
Expand Up @@ -61,6 +61,7 @@ Bristol.prototype.addTarget = function(target, options) {
target = require('./targets/' + target);
var targetObj = {
log: target.bind(target, options || {}),
restart: target.restart || function () {},
formatter: DEFAULT_FORMATTER.bind(this, [{}]),
blacklist: {},
whitelist: {},
Expand Down Expand Up @@ -361,5 +362,15 @@ Bristol.prototype._transform = function(elem) {
return result || elem;
};

/**
* Calls restart on all targets; for example, to support closing and reopening
* files for log rotation
*/
Bristol.prototype.restart = function () {
this._targets.forEach(function(target) {
target.restart();
});
}

module.exports = new Bristol();
module.exports.Bristol = Bristol;
7 changes: 7 additions & 0 deletions lib/targets/file.js
Expand Up @@ -41,4 +41,11 @@ function log(options, severity, date, message) {
out.write(message + "\n");
}

log.restart = function () {
for (key in streams) {
streams[key].end();
}
streams = {};
}

module.exports = log;

0 comments on commit c8957c7

Please sign in to comment.