diff --git a/lib/winston-loggly.js b/lib/winston-loggly.js index 2bf511b..0fa7634 100644 --- a/lib/winston-loggly.js +++ b/lib/winston-loggly.js @@ -17,6 +17,8 @@ var events = require('events'), // var code = /\u001b\[(\d+(;\d+)*)?m/g; +var timerFunctionForProcessExit = null; + // // ### function Loggly (options) // #### @options {Object} Options for this instance. @@ -62,6 +64,18 @@ var Loggly = exports.Loggly = function (options) { this.stripColors = options.stripColors || false; }; +// +// Helper function to call process.exit() after waiting +// 10 seconds. +// +var flushLogsAndExit = exports.flushLogsAndExit = function () { + if (timerFunctionForProcessExit === null) { + timerFunctionForProcessExit = setInterval(function () { + process.exit(); + },10000); + } +} + // // Inherit from `winston.Transport`. // @@ -72,6 +86,7 @@ util.inherits(Loggly, winston.Transport); // is available and thus backwards compatible. // winston.transports.Loggly = Loggly; +winston.transports.flushLogsAndExit = flushLogsAndExit; // // Expose the name of this Transport on the prototype