{"action":"created","comment":{"url":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/comments/44357613","id":44357613,"diff_hunk":"@@ -474,27 +655,32 @@ SplunkLogger.prototype.send = function (context, callback) {\n  * @param {function} [callback] - A callback function: <code>function(err, response, body)</code>.\n  * @public\n  */\n-SplunkLogger.prototype.flush = function (callback) {\n+SplunkLogger.prototype.flush = function(callback) {\n     callback = callback || function(){};\n \n     var context = {};\n \n-    // Use the batching setting from this.config\n-    if (this.config.autoFlush) {\n-        // TODO: handle case of multiple events with autoFlush off, flushing fast\n-        // Just take the oldest event in the queue\n-        context = this.contextQueue.pop();\n-    }\n-    else {\n-        // Empty the event queue\n+    var batchOverSize = this.config.maxBatchSize > 0 && this.calculateBatchSize() > this.config.maxBatchSize;\n+    var batchOverCount = this.config.maxBatchCount > 0 && this.contextQueue.length >= this.config.maxBatchCount;\n+    var isBatched = !this.config.autoFlush || (this.config.autoFlush && (batchOverSize || batchOverCount || this._timerID));\n+\n+    // Empty the queue if manual/interval/size/count batching\n+    if (isBatched) {\n         var queue = this.contextQueue;\n         this.contextQueue = [];\n+        this.eventSizes = [];\n         var data = \"\";\n         for (var i = 0; i < queue.length; i++) {\n             data += JSON.stringify(this._makeBody(queue[i]));\n         }\n         context.message = data;\n     }\n+    // Just take the oldest event in the queue\n+    else {\n+        // TODO: handle case of multiple events with autoFlush off, flushing fast","path":"splunklogger.js","position":382,"original_position":382,"commit_id":"806b2206942472c5487f33d9f9509503339e18bd","original_commit_id":"806b2206942472c5487f33d9f9509503339e18bd","user":{"login":"itay","id":3266,"avatar_url":"https://avatars.githubusercontent.com/u/3266?v=3","gravatar_id":"","url":"https://api.github.com/users/itay","html_url":"https://github.com/itay","followers_url":"https://api.github.com/users/itay/followers","following_url":"https://api.github.com/users/itay/following{/other_user}","gists_url":"https://api.github.com/users/itay/gists{/gist_id}","starred_url":"https://api.github.com/users/itay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itay/subscriptions","organizations_url":"https://api.github.com/users/itay/orgs","repos_url":"https://api.github.com/users/itay/repos","events_url":"https://api.github.com/users/itay/events{/privacy}","received_events_url":"https://api.github.com/users/itay/received_events","type":"User","site_admin":false},"body":"I don't understand this case. If I have autoFlush off, and I manually call `flush()`, it should just send everything thats queued up at the moment.","created_at":"2015-11-10T01:00:20Z","updated_at":"2015-11-10T01:00:20Z","html_url":"https://github.com/splunk/splunk-javascript-logging/pull/1#discussion_r44357613","pull_request_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/comments/44357613"},"html":{"href":"https://github.com/splunk/splunk-javascript-logging/pull/1#discussion_r44357613"},"pull_request":{"href":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/1","id":50196775,"html_url":"https://github.com/splunk/splunk-javascript-logging/pull/1","diff_url":"https://github.com/splunk/splunk-javascript-logging/pull/1.diff","patch_url":"https://github.com/splunk/splunk-javascript-logging/pull/1.patch","issue_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues/1","number":1,"state":"open","locked":false,"title":"Added retry logic & batching settings","user":{"login":"shakeelmohamed","id":1480063,"avatar_url":"https://avatars.githubusercontent.com/u/1480063?v=3","gravatar_id":"","url":"https://api.github.com/users/shakeelmohamed","html_url":"https://github.com/shakeelmohamed","followers_url":"https://api.github.com/users/shakeelmohamed/followers","following_url":"https://api.github.com/users/shakeelmohamed/following{/other_user}","gists_url":"https://api.github.com/users/shakeelmohamed/gists{/gist_id}","starred_url":"https://api.github.com/users/shakeelmohamed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shakeelmohamed/subscriptions","organizations_url":"https://api.github.com/users/shakeelmohamed/orgs","repos_url":"https://api.github.com/users/shakeelmohamed/repos","events_url":"https://api.github.com/users/shakeelmohamed/events{/privacy}","received_events_url":"https://api.github.com/users/shakeelmohamed/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-10T00:03:40Z","updated_at":"2015-11-10T01:00:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b0e95e82de58d4d135e2188d732b8e33d89279b2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/1/commits","review_comments_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/1/comments","review_comment_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/comments{/number}","comments_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues/1/comments","statuses_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/statuses/806b2206942472c5487f33d9f9509503339e18bd","head":{"label":"splunk:feature/batch-event-count","ref":"feature/batch-event-count","sha":"806b2206942472c5487f33d9f9509503339e18bd","user":{"login":"splunk","id":651467,"avatar_url":"https://avatars.githubusercontent.com/u/651467?v=3","gravatar_id":"","url":"https://api.github.com/users/splunk","html_url":"https://github.com/splunk","followers_url":"https://api.github.com/users/splunk/followers","following_url":"https://api.github.com/users/splunk/following{/other_user}","gists_url":"https://api.github.com/users/splunk/gists{/gist_id}","starred_url":"https://api.github.com/users/splunk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/splunk/subscriptions","organizations_url":"https://api.github.com/users/splunk/orgs","repos_url":"https://api.github.com/users/splunk/repos","events_url":"https://api.github.com/users/splunk/events{/privacy}","received_events_url":"https://api.github.com/users/splunk/received_events","type":"Organization","site_admin":false},"repo":{"id":42700977,"name":"splunk-javascript-logging","full_name":"splunk/splunk-javascript-logging","owner":{"login":"splunk","id":651467,"avatar_url":"https://avatars.githubusercontent.com/u/651467?v=3","gravatar_id":"","url":"https://api.github.com/users/splunk","html_url":"https://github.com/splunk","followers_url":"https://api.github.com/users/splunk/followers","following_url":"https://api.github.com/users/splunk/following{/other_user}","gists_url":"https://api.github.com/users/splunk/gists{/gist_id}","starred_url":"https://api.github.com/users/splunk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/splunk/subscriptions","organizations_url":"https://api.github.com/users/splunk/orgs","repos_url":"https://api.github.com/users/splunk/repos","events_url":"https://api.github.com/users/splunk/events{/privacy}","received_events_url":"https://api.github.com/users/splunk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/splunk/splunk-javascript-logging","description":"Splunk HTTP Event Collector logging interface for JavaScript","fork":false,"url":"https://api.github.com/repos/splunk/splunk-javascript-logging","forks_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/forks","keys_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/keys{/key_id}","collaborators_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/teams","hooks_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/hooks","issue_events_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues/events{/number}","events_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/events","assignees_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/assignees{/user}","branches_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/branches{/branch}","tags_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/tags","blobs_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/refs{/sha}","trees_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/trees{/sha}","statuses_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/statuses/{sha}","languages_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/languages","stargazers_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/stargazers","contributors_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/contributors","subscribers_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/subscribers","subscription_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/subscription","commits_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/commits{/sha}","git_commits_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/commits{/sha}","comments_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/comments{/number}","issue_comment_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues/comments{/number}","contents_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/contents/{+path}","compare_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/compare/{base}...{head}","merges_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/merges","archive_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/downloads","issues_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues{/number}","pulls_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls{/number}","milestones_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/milestones{/number}","notifications_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/labels{/name}","releases_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/releases{/id}","created_at":"2015-09-18T05:13:12Z","updated_at":"2015-10-24T09:11:45Z","pushed_at":"2015-11-10T00:03:40Z","git_url":"git://github.com/splunk/splunk-javascript-logging.git","ssh_url":"git@github.com:splunk/splunk-javascript-logging.git","clone_url":"https://github.com/splunk/splunk-javascript-logging.git","svn_url":"https://github.com/splunk/splunk-javascript-logging","homepage":"http://dev.splunk.com/view/splunk-logging-javascript/SP-CAAAE63","size":247,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":3,"default_branch":"master"}},"base":{"label":"splunk:develop","ref":"develop","sha":"8315fe81b3f60eb772f5bb65995baf5daa31ffff","user":{"login":"splunk","id":651467,"avatar_url":"https://avatars.githubusercontent.com/u/651467?v=3","gravatar_id":"","url":"https://api.github.com/users/splunk","html_url":"https://github.com/splunk","followers_url":"https://api.github.com/users/splunk/followers","following_url":"https://api.github.com/users/splunk/following{/other_user}","gists_url":"https://api.github.com/users/splunk/gists{/gist_id}","starred_url":"https://api.github.com/users/splunk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/splunk/subscriptions","organizations_url":"https://api.github.com/users/splunk/orgs","repos_url":"https://api.github.com/users/splunk/repos","events_url":"https://api.github.com/users/splunk/events{/privacy}","received_events_url":"https://api.github.com/users/splunk/received_events","type":"Organization","site_admin":false},"repo":{"id":42700977,"name":"splunk-javascript-logging","full_name":"splunk/splunk-javascript-logging","owner":{"login":"splunk","id":651467,"avatar_url":"https://avatars.githubusercontent.com/u/651467?v=3","gravatar_id":"","url":"https://api.github.com/users/splunk","html_url":"https://github.com/splunk","followers_url":"https://api.github.com/users/splunk/followers","following_url":"https://api.github.com/users/splunk/following{/other_user}","gists_url":"https://api.github.com/users/splunk/gists{/gist_id}","starred_url":"https://api.github.com/users/splunk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/splunk/subscriptions","organizations_url":"https://api.github.com/users/splunk/orgs","repos_url":"https://api.github.com/users/splunk/repos","events_url":"https://api.github.com/users/splunk/events{/privacy}","received_events_url":"https://api.github.com/users/splunk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/splunk/splunk-javascript-logging","description":"Splunk HTTP Event Collector logging interface for JavaScript","fork":false,"url":"https://api.github.com/repos/splunk/splunk-javascript-logging","forks_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/forks","keys_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/keys{/key_id}","collaborators_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/teams","hooks_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/hooks","issue_events_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues/events{/number}","events_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/events","assignees_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/assignees{/user}","branches_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/branches{/branch}","tags_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/tags","blobs_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/refs{/sha}","trees_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/trees{/sha}","statuses_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/statuses/{sha}","languages_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/languages","stargazers_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/stargazers","contributors_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/contributors","subscribers_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/subscribers","subscription_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/subscription","commits_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/commits{/sha}","git_commits_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/git/commits{/sha}","comments_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/comments{/number}","issue_comment_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues/comments{/number}","contents_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/contents/{+path}","compare_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/compare/{base}...{head}","merges_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/merges","archive_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/downloads","issues_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues{/number}","pulls_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls{/number}","milestones_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/milestones{/number}","notifications_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/labels{/name}","releases_url":"https://api.github.com/repos/splunk/splunk-javascript-logging/releases{/id}","created_at":"2015-09-18T05:13:12Z","updated_at":"2015-10-24T09:11:45Z","pushed_at":"2015-11-10T00:03:40Z","git_url":"git://github.com/splunk/splunk-javascript-logging.git","ssh_url":"git@github.com:splunk/splunk-javascript-logging.git","clone_url":"https://github.com/splunk/splunk-javascript-logging.git","svn_url":"https://github.com/splunk/splunk-javascript-logging","homepage":"http://dev.splunk.com/view/splunk-logging-javascript/SP-CAAAE63","size":247,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/1"},"html":{"href":"https://github.com/splunk/splunk-javascript-logging/pull/1"},"issue":{"href":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues/1"},"comments":{"href":"https://api.github.com/repos/splunk/splunk-javascript-logging/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/splunk/splunk-javascript-logging/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/splunk/splunk-javascript-logging/statuses/806b2206942472c5487f33d9f9509503339e18bd"}}}}