{"action":"created","comment":{"url":"https://api.github.com/repos/electricimp/Loggly/pulls/comments/34286759","id":34286759,"diff_hunk":"@@ -0,0 +1,138 @@\n+class Loggly {\n+    static version = [1,0,0];\n+\n+    static LOG_URL = \"https://logs-01.loggly.com/bulk/%s/tag/%s/\"\n+\n+    static LOG  = \"LOG\";\n+    static WARN = \"WARNING\";\n+    static ERR  = \"ERROR\";\n+\n+    _token = null;          // The customer token\n+    _id = null;             // ID (default: agentID)\n+    _tag = null;            // The log Tag (default: electricimp)\n+    _timeout = null;        // Send frequency (default: 15s)\n+    _debug = null;          // whether or not to server.log (default: true)\n+\n+    _url = null;            // The URL we send reqeusts to\n+    _logString = null;      // The current set of logs that are queued for send\n+\n+    _onError = null;        // The onError handler for when there's a problem with the logs\n+    _timer = null;          // The watchdog's timer object\n+\n+    constructor(token, options = {}) {\n+        _token = token;\n+\n+        // Grab any settings\n+        _id = \"id\" in options ? options.id : split(http.agenturl(), \"/\").pop();\n+        _tag = \"tag\" in options ? options.tag : \"electricimp\"\n+        _timeout = \"timeout\" in options ? options.timeout : 15;\n+        _debug = \"debug\" in options ? options.debug : true;\n+\n+        // Generate the URL\n+        _url = _generateUrl()\n+\n+        // initialize _logString\n+        _logString = \"\";\n+\n+        // Start the send loop\n+        _timer = imp.wakeup(_timeout, send.bindenv(this));\n+    }\n+\n+    function log(msg, ...) {\n+        _push(LOG, msg, vargv);\n+    }\n+\n+    function warn(msg, ...) {\n+        _push(WARN, msg, vargv);\n+    }\n+\n+    function error(msg, ...) {\n+        _push(ERR, msg, vargv);\n+    }\n+\n+    function send() {\n+        // reset the timer object\n+        if (_timer != null) imp.cancelwakeup(_timer);\n+        _timer = imp.wakeup(_timeout, send.bindenv(this));\n+\n+        // if there's nothing to log, we're done\n+        if (_logString.len() == 0) return;\n+\n+        // Grab the logs, and clear\n+        local logs = _logString;\n+        _logString = \"\";\n+\n+        // Send the logs\n+        http.post(_url, {}, logs).sendasync(function(resp) {\n+            if (resp.statuscode != 200) {\n+                // If an error occured, add the logs back in\n+                _logString += logs;\n+\n+                if (_onError != null) {\n+                    local __this = this;\n+                    imp.wakeup(0, function() { __this._onError(resp); });\n+                } else {\n+                    server.error(\"Loggly send failed:\");\n+                    server.error(\"   \" + resp.statuscode + \" - \" + resp.body);\n+                }\n+            } else {\n+                server.log(\"success!\");\n+                // nothing\n+            }\n+        }.bindenv(this));\n+    }\n+\n+    function len() {\n+        return split(_logString, \"\\n\").len();\n+    }\n+\n+\n+    function onError(cb) {\n+        _onError = cb;\n+    }\n+\n+    static function ISODateTime(ts = null) {\n+        if (ts == null) ts = time();\n+        local datetime = date(ts);\n+        return format(\"%04i-%02i-%02iT%02i:%02i:%02iZ\",\n+            datetime.year, datetime.month+1, datetime.day,\n+            datetime.hour, datetime.min, datetime.sec);\n+    }\n+\n+    //-------------------- PRIVATE METHODS --------------------//\n+    // Addes a log to the _logString\n+    function _push(level, msg, argv = []) {\n+        local json = {\n+            \"id\": _id,\n+            \"level\": level,\n+            \"timestamp\": ISODateTime()\n+        };\n+\n+        if (typeof(msg) == \"string\") {\n+            local args = [this, msg];\n+            if (argv.len() > 0 && typeof(argv[0]) == \"array\") {","path":"Loggly.class.nut","position":113,"original_position":113,"commit_id":"f5b0f8869ac506e35e5a8edf661eaa4cc9da2347","original_commit_id":"f5b0f8869ac506e35e5a8edf661eaa4cc9da2347","user":{"login":"DoronShapiro","id":1010842,"avatar_url":"https://avatars.githubusercontent.com/u/1010842?v=3","gravatar_id":"","url":"https://api.github.com/users/DoronShapiro","html_url":"https://github.com/DoronShapiro","followers_url":"https://api.github.com/users/DoronShapiro/followers","following_url":"https://api.github.com/users/DoronShapiro/following{/other_user}","gists_url":"https://api.github.com/users/DoronShapiro/gists{/gist_id}","starred_url":"https://api.github.com/users/DoronShapiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DoronShapiro/subscriptions","organizations_url":"https://api.github.com/users/DoronShapiro/orgs","repos_url":"https://api.github.com/users/DoronShapiro/repos","events_url":"https://api.github.com/users/DoronShapiro/events{/privacy}","received_events_url":"https://api.github.com/users/DoronShapiro/received_events","type":"User","site_admin":false},"body":"What is the case when this is used?","created_at":"2015-07-09T18:25:23Z","updated_at":"2015-07-09T18:25:23Z","html_url":"https://github.com/electricimp/Loggly/pull/1#discussion_r34286759","pull_request_url":"https://api.github.com/repos/electricimp/Loggly/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/electricimp/Loggly/pulls/comments/34286759"},"html":{"href":"https://github.com/electricimp/Loggly/pull/1#discussion_r34286759"},"pull_request":{"href":"https://api.github.com/repos/electricimp/Loggly/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/electricimp/Loggly/pulls/1","id":39602729,"html_url":"https://github.com/electricimp/Loggly/pull/1","diff_url":"https://github.com/electricimp/Loggly/pull/1.diff","patch_url":"https://github.com/electricimp/Loggly/pull/1.patch","issue_url":"https://api.github.com/repos/electricimp/Loggly/issues/1","number":1,"state":"open","locked":false,"title":"V1.0.0","user":{"login":"beardedinventor","id":1187089,"avatar_url":"https://avatars.githubusercontent.com/u/1187089?v=3","gravatar_id":"","url":"https://api.github.com/users/beardedinventor","html_url":"https://github.com/beardedinventor","followers_url":"https://api.github.com/users/beardedinventor/followers","following_url":"https://api.github.com/users/beardedinventor/following{/other_user}","gists_url":"https://api.github.com/users/beardedinventor/gists{/gist_id}","starred_url":"https://api.github.com/users/beardedinventor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beardedinventor/subscriptions","organizations_url":"https://api.github.com/users/beardedinventor/orgs","repos_url":"https://api.github.com/users/beardedinventor/repos","events_url":"https://api.github.com/users/beardedinventor/events{/privacy}","received_events_url":"https://api.github.com/users/beardedinventor/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-09T16:32:39Z","updated_at":"2015-07-09T18:25:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"17ce1dad2ad2785a09ebe1dbac35644176e45406","assignee":{"login":"DoronShapiro","id":1010842,"avatar_url":"https://avatars.githubusercontent.com/u/1010842?v=3","gravatar_id":"","url":"https://api.github.com/users/DoronShapiro","html_url":"https://github.com/DoronShapiro","followers_url":"https://api.github.com/users/DoronShapiro/followers","following_url":"https://api.github.com/users/DoronShapiro/following{/other_user}","gists_url":"https://api.github.com/users/DoronShapiro/gists{/gist_id}","starred_url":"https://api.github.com/users/DoronShapiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DoronShapiro/subscriptions","organizations_url":"https://api.github.com/users/DoronShapiro/orgs","repos_url":"https://api.github.com/users/DoronShapiro/repos","events_url":"https://api.github.com/users/DoronShapiro/events{/privacy}","received_events_url":"https://api.github.com/users/DoronShapiro/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/electricimp/Loggly/pulls/1/commits","review_comments_url":"https://api.github.com/repos/electricimp/Loggly/pulls/1/comments","review_comment_url":"https://api.github.com/repos/electricimp/Loggly/pulls/comments{/number}","comments_url":"https://api.github.com/repos/electricimp/Loggly/issues/1/comments","statuses_url":"https://api.github.com/repos/electricimp/Loggly/statuses/f5b0f8869ac506e35e5a8edf661eaa4cc9da2347","head":{"label":"electricimp:v1.0.0","ref":"v1.0.0","sha":"f5b0f8869ac506e35e5a8edf661eaa4cc9da2347","user":{"login":"electricimp","id":3960327,"avatar_url":"https://avatars.githubusercontent.com/u/3960327?v=3","gravatar_id":"","url":"https://api.github.com/users/electricimp","html_url":"https://github.com/electricimp","followers_url":"https://api.github.com/users/electricimp/followers","following_url":"https://api.github.com/users/electricimp/following{/other_user}","gists_url":"https://api.github.com/users/electricimp/gists{/gist_id}","starred_url":"https://api.github.com/users/electricimp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electricimp/subscriptions","organizations_url":"https://api.github.com/users/electricimp/orgs","repos_url":"https://api.github.com/users/electricimp/repos","events_url":"https://api.github.com/users/electricimp/events{/privacy}","received_events_url":"https://api.github.com/users/electricimp/received_events","type":"Organization","site_admin":false},"repo":{"id":38832220,"name":"Loggly","full_name":"electricimp/Loggly","owner":{"login":"electricimp","id":3960327,"avatar_url":"https://avatars.githubusercontent.com/u/3960327?v=3","gravatar_id":"","url":"https://api.github.com/users/electricimp","html_url":"https://github.com/electricimp","followers_url":"https://api.github.com/users/electricimp/followers","following_url":"https://api.github.com/users/electricimp/following{/other_user}","gists_url":"https://api.github.com/users/electricimp/gists{/gist_id}","starred_url":"https://api.github.com/users/electricimp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electricimp/subscriptions","organizations_url":"https://api.github.com/users/electricimp/orgs","repos_url":"https://api.github.com/users/electricimp/repos","events_url":"https://api.github.com/users/electricimp/events{/privacy}","received_events_url":"https://api.github.com/users/electricimp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/electricimp/Loggly","description":"Wrapper class for the Loggly API","fork":false,"url":"https://api.github.com/repos/electricimp/Loggly","forks_url":"https://api.github.com/repos/electricimp/Loggly/forks","keys_url":"https://api.github.com/repos/electricimp/Loggly/keys{/key_id}","collaborators_url":"https://api.github.com/repos/electricimp/Loggly/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/electricimp/Loggly/teams","hooks_url":"https://api.github.com/repos/electricimp/Loggly/hooks","issue_events_url":"https://api.github.com/repos/electricimp/Loggly/issues/events{/number}","events_url":"https://api.github.com/repos/electricimp/Loggly/events","assignees_url":"https://api.github.com/repos/electricimp/Loggly/assignees{/user}","branches_url":"https://api.github.com/repos/electricimp/Loggly/branches{/branch}","tags_url":"https://api.github.com/repos/electricimp/Loggly/tags","blobs_url":"https://api.github.com/repos/electricimp/Loggly/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/electricimp/Loggly/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/electricimp/Loggly/git/refs{/sha}","trees_url":"https://api.github.com/repos/electricimp/Loggly/git/trees{/sha}","statuses_url":"https://api.github.com/repos/electricimp/Loggly/statuses/{sha}","languages_url":"https://api.github.com/repos/electricimp/Loggly/languages","stargazers_url":"https://api.github.com/repos/electricimp/Loggly/stargazers","contributors_url":"https://api.github.com/repos/electricimp/Loggly/contributors","subscribers_url":"https://api.github.com/repos/electricimp/Loggly/subscribers","subscription_url":"https://api.github.com/repos/electricimp/Loggly/subscription","commits_url":"https://api.github.com/repos/electricimp/Loggly/commits{/sha}","git_commits_url":"https://api.github.com/repos/electricimp/Loggly/git/commits{/sha}","comments_url":"https://api.github.com/repos/electricimp/Loggly/comments{/number}","issue_comment_url":"https://api.github.com/repos/electricimp/Loggly/issues/comments{/number}","contents_url":"https://api.github.com/repos/electricimp/Loggly/contents/{+path}","compare_url":"https://api.github.com/repos/electricimp/Loggly/compare/{base}...{head}","merges_url":"https://api.github.com/repos/electricimp/Loggly/merges","archive_url":"https://api.github.com/repos/electricimp/Loggly/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/electricimp/Loggly/downloads","issues_url":"https://api.github.com/repos/electricimp/Loggly/issues{/number}","pulls_url":"https://api.github.com/repos/electricimp/Loggly/pulls{/number}","milestones_url":"https://api.github.com/repos/electricimp/Loggly/milestones{/number}","notifications_url":"https://api.github.com/repos/electricimp/Loggly/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/electricimp/Loggly/labels{/name}","releases_url":"https://api.github.com/repos/electricimp/Loggly/releases{/id}","created_at":"2015-07-09T16:28:53Z","updated_at":"2015-07-09T16:28:53Z","pushed_at":"2015-07-09T16:32:40Z","git_url":"git://github.com/electricimp/Loggly.git","ssh_url":"git@github.com:electricimp/Loggly.git","clone_url":"https://github.com/electricimp/Loggly.git","svn_url":"https://github.com/electricimp/Loggly","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"electricimp:master","ref":"master","sha":"889197307525b35e46800ccd3525f69303cac7e7","user":{"login":"electricimp","id":3960327,"avatar_url":"https://avatars.githubusercontent.com/u/3960327?v=3","gravatar_id":"","url":"https://api.github.com/users/electricimp","html_url":"https://github.com/electricimp","followers_url":"https://api.github.com/users/electricimp/followers","following_url":"https://api.github.com/users/electricimp/following{/other_user}","gists_url":"https://api.github.com/users/electricimp/gists{/gist_id}","starred_url":"https://api.github.com/users/electricimp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electricimp/subscriptions","organizations_url":"https://api.github.com/users/electricimp/orgs","repos_url":"https://api.github.com/users/electricimp/repos","events_url":"https://api.github.com/users/electricimp/events{/privacy}","received_events_url":"https://api.github.com/users/electricimp/received_events","type":"Organization","site_admin":false},"repo":{"id":38832220,"name":"Loggly","full_name":"electricimp/Loggly","owner":{"login":"electricimp","id":3960327,"avatar_url":"https://avatars.githubusercontent.com/u/3960327?v=3","gravatar_id":"","url":"https://api.github.com/users/electricimp","html_url":"https://github.com/electricimp","followers_url":"https://api.github.com/users/electricimp/followers","following_url":"https://api.github.com/users/electricimp/following{/other_user}","gists_url":"https://api.github.com/users/electricimp/gists{/gist_id}","starred_url":"https://api.github.com/users/electricimp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electricimp/subscriptions","organizations_url":"https://api.github.com/users/electricimp/orgs","repos_url":"https://api.github.com/users/electricimp/repos","events_url":"https://api.github.com/users/electricimp/events{/privacy}","received_events_url":"https://api.github.com/users/electricimp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/electricimp/Loggly","description":"Wrapper class for the Loggly API","fork":false,"url":"https://api.github.com/repos/electricimp/Loggly","forks_url":"https://api.github.com/repos/electricimp/Loggly/forks","keys_url":"https://api.github.com/repos/electricimp/Loggly/keys{/key_id}","collaborators_url":"https://api.github.com/repos/electricimp/Loggly/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/electricimp/Loggly/teams","hooks_url":"https://api.github.com/repos/electricimp/Loggly/hooks","issue_events_url":"https://api.github.com/repos/electricimp/Loggly/issues/events{/number}","events_url":"https://api.github.com/repos/electricimp/Loggly/events","assignees_url":"https://api.github.com/repos/electricimp/Loggly/assignees{/user}","branches_url":"https://api.github.com/repos/electricimp/Loggly/branches{/branch}","tags_url":"https://api.github.com/repos/electricimp/Loggly/tags","blobs_url":"https://api.github.com/repos/electricimp/Loggly/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/electricimp/Loggly/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/electricimp/Loggly/git/refs{/sha}","trees_url":"https://api.github.com/repos/electricimp/Loggly/git/trees{/sha}","statuses_url":"https://api.github.com/repos/electricimp/Loggly/statuses/{sha}","languages_url":"https://api.github.com/repos/electricimp/Loggly/languages","stargazers_url":"https://api.github.com/repos/electricimp/Loggly/stargazers","contributors_url":"https://api.github.com/repos/electricimp/Loggly/contributors","subscribers_url":"https://api.github.com/repos/electricimp/Loggly/subscribers","subscription_url":"https://api.github.com/repos/electricimp/Loggly/subscription","commits_url":"https://api.github.com/repos/electricimp/Loggly/commits{/sha}","git_commits_url":"https://api.github.com/repos/electricimp/Loggly/git/commits{/sha}","comments_url":"https://api.github.com/repos/electricimp/Loggly/comments{/number}","issue_comment_url":"https://api.github.com/repos/electricimp/Loggly/issues/comments{/number}","contents_url":"https://api.github.com/repos/electricimp/Loggly/contents/{+path}","compare_url":"https://api.github.com/repos/electricimp/Loggly/compare/{base}...{head}","merges_url":"https://api.github.com/repos/electricimp/Loggly/merges","archive_url":"https://api.github.com/repos/electricimp/Loggly/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/electricimp/Loggly/downloads","issues_url":"https://api.github.com/repos/electricimp/Loggly/issues{/number}","pulls_url":"https://api.github.com/repos/electricimp/Loggly/pulls{/number}","milestones_url":"https://api.github.com/repos/electricimp/Loggly/milestones{/number}","notifications_url":"https://api.github.com/repos/electricimp/Loggly/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/electricimp/Loggly/labels{/name}","releases_url":"https://api.github.com/repos/electricimp/Loggly/releases{/id}","created_at":"2015-07-09T16:28:53Z","updated_at":"2015-07-09T16:28:53Z","pushed_at":"2015-07-09T16:32:40Z","git_url":"git://github.com/electricimp/Loggly.git","ssh_url":"git@github.com:electricimp/Loggly.git","clone_url":"https://github.com/electricimp/Loggly.git","svn_url":"https://github.com/electricimp/Loggly","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/electricimp/Loggly/pulls/1"},"html":{"href":"https://github.com/electricimp/Loggly/pull/1"},"issue":{"href":"https://api.github.com/repos/electricimp/Loggly/issues/1"},"comments":{"href":"https://api.github.com/repos/electricimp/Loggly/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/electricimp/Loggly/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/electricimp/Loggly/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/electricimp/Loggly/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/electricimp/Loggly/statuses/f5b0f8869ac506e35e5a8edf661eaa4cc9da2347"}}}}