From b08406da2104e2fe7de0c11c33baece350713299 Mon Sep 17 00:00:00 2001 From: Shwetajain148 Date: Wed, 9 Aug 2017 14:52:12 +0530 Subject: [PATCH 1/3] update README.md file for flushLogsAndExit function --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 91b5384..9cf7070 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,23 @@ bufferOptions: { ``` * __Note:__ The default value of buffer size and retries in milliseconds are 500 and 30000 (30 seconds) respectively. +## Flush logs and exit + +Our library uses ajax requests to send logs to Loggly and ajax requests take time to complete, in that case if you call process.exit() externally in your application then it is certain that as soon as process.exit() will be called, your application will exit and all the queued requests will be interrupted and your application logs will also not reach to Loggly. + +To support this scenario in which you really want to call process.exit() without losting logs, we have a function called flushLogsAndExit() which waits for 10 seconds and then call process.exit() itself. By doing so, logging will be complete in given time and then your apllication will exit. + +You have to do something like below code snippet: + +``` js +var winston = require('winston'), +winlog = require('winston-loggly-bulk'); + +winston.log("info", "hello World"); +winlog.flushLogsAndExit(); + +``` + ## Motivation `tldr;?`: To break the [winston][1] codebase into small modules that work together. From 4caebd2d37def37a8077fa24e65317dc620d3858 Mon Sep 17 00:00:00 2001 From: Jason Skowronski Date: Wed, 9 Aug 2017 09:28:05 -0700 Subject: [PATCH 2/3] Update README.md --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9cf7070..3d7aaa6 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ A client implementation for Loggly in node.js. Check out Loggly's [Node logging // Requiring `winston-loggly-bulk` will expose // `winston.transports.Loggly` // - require('winston-loggly-bulk'); + require('winston-loggly-bulk'); winston.add(winston.transports.Loggly, options); ``` @@ -56,11 +56,9 @@ bufferOptions: { ## Flush logs and exit -Our library uses ajax requests to send logs to Loggly and ajax requests take time to complete, in that case if you call process.exit() externally in your application then it is certain that as soon as process.exit() will be called, your application will exit and all the queued requests will be interrupted and your application logs will also not reach to Loggly. +Our library uses ajax requests to send logs to Loggly, and as ajax requests take time to complete, logs can be lost when process.exit() is called because it forces an immediate exit. To exit gracefully and ensure that the last logs get to Loggly, we created a function called flushLogsAndExit(). It waits for 10 seconds and then calls process.exit() itself. This allows enough time for the logs to be sent to Loggly. -To support this scenario in which you really want to call process.exit() without losting logs, we have a function called flushLogsAndExit() which waits for 10 seconds and then call process.exit() itself. By doing so, logging will be complete in given time and then your apllication will exit. - -You have to do something like below code snippet: +Here is an example of how to use the method: ``` js var winston = require('winston'), From 4d2472225749bfc4312038a906d08072f8517365 Mon Sep 17 00:00:00 2001 From: Jason Skowronski Date: Wed, 9 Aug 2017 09:29:17 -0700 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d7aaa6..1d3d672 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ A client implementation for Loggly in node.js. Check out Loggly's [Node logging // Requiring `winston-loggly-bulk` will expose // `winston.transports.Loggly` // - require('winston-loggly-bulk'); + require('winston-loggly-bulk'); winston.add(winston.transports.Loggly, options); ```