From 4a2770c034dfa416aa0be48a883a1925d734bd59 Mon Sep 17 00:00:00 2001 From: Shweta Jain Date: Tue, 8 Aug 2017 17:52:09 +0530 Subject: [PATCH] helper method to call process exit --- lib/winston-loggly.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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