{"action":"created","comment":{"url":"https://api.github.com/repos/vatesfr/xo-server/pulls/comments/45208086","id":45208086,"diff_hunk":"@@ -0,0 +1,191 @@\n+import appConf from 'app-conf'\n+import get from 'lodash.get'\n+import highland from 'highland'\n+import levelup from 'level-party'\n+import ndjson from 'ndjson'\n+import parseArgs from 'minimist'\n+import sublevel from 'level-sublevel'\n+import util from 'util'\n+\n+import globMatcher from './glob-matcher'\n+\n+// ===================================================================\n+\n+async function printLogs (db, args) {\n+  let stream = highland(db.createReadStream({reverse: true}))\n+\n+  if (args.since) {\n+    stream = stream.filter(({value}) => (value.time >= args.since))\n+  }\n+\n+  if (args.until) {\n+    stream = stream.filter(({value}) => (value.time <= args.until))\n+  }\n+\n+  const fields = Object.keys(args.matchers)\n+\n+  if (fields.length > 0) {\n+    stream = stream.filter(({value}) => {\n+      for (const field of fields) {\n+        const fieldValue = get(value, field)\n+        if (fieldValue === undefined || !args.matchers[field](fieldValue)) {\n+          return false\n+        }\n+      }\n+\n+      return true\n+    })\n+  }\n+\n+  stream = stream.take(args.limit)\n+\n+  if (args.json) {\n+    stream = highland(stream.pipe(ndjson.serialize()))\n+      .each(value => {\n+        process.stdout.write(value)\n+      })\n+  } else {\n+    stream = stream.each(value => {\n+      console.log(util.inspect(value, { depth: null }))\n+    })\n+  }\n+\n+  return new Promise(resolve => {\n+    stream.done(resolve)\n+  })\n+}\n+\n+// ===================================================================\n+\n+function helper () {\n+  console.error(\n+  `Usage:\n+  xo-server-logs --help, -h\n+  xo-server-logs [--json] [--limit=<limit>] [--since=<date>] [--until=<date>] [<pattern>...]\n+\n+    --help\n+        Display this help message.\n+\n+    --json\n+        Display the results as new line delimited JSON for consumption by another program.\n+\n+    --limit=<limit>, -n <limit>\n+        Limit the number of results to be displayed (default 100)\n+\n+    --since=<date>, --until=<date>\n+        Start showing entries on or newer than the specified date, or on or older than the specified date.\n+        <date> should use the format \\`YYYY-MM-DD\\`.\n+\n+    <pattern>\n+        Patterns can be used to filter the entries.\n+        <pattern> have the following format \\`<field>=<value>\\`/\\`<field>\\`.`\n+  )\n+}\n+\n+// ===================================================================\n+\n+function getArgs () {\n+  const stringArgs = ['since', 'until', 'limit']\n+  const args = parseArgs(process.argv.slice(2), {\n+    string: stringArgs,\n+    boolean: ['help', 'json'],\n+    default: {\n+      limit: 100,\n+      json: false,\n+      help: false\n+    },\n+    alias: {\n+      limit: 'n',\n+      help: 'h'\n+    }\n+  })\n+\n+  const patterns = {}\n+\n+  for (const value of args._) {\n+    const arr = value.toString().split('=')\n+\n+    if (patterns[arr[0]] === null) {\n+      continue\n+    }\n+\n+    if (arr.length < 2) {\n+      patterns[arr[0]] = null\n+    } else {\n+      if (patterns[arr[0]] === undefined) {\n+        patterns[arr[0]] = []\n+      }\n+\n+      patterns[arr[0]].push(arr[1])\n+    }\n+  }\n+\n+  args.matchers = {}\n+\n+  for (const field in patterns) {\n+    if (patterns[field] === null) {","path":"src/logs-cli.js","position":126,"original_position":126,"commit_id":"448f24e33637ffc7846d6e0fbf0bdb1701b283d3","original_commit_id":"448f24e33637ffc7846d6e0fbf0bdb1701b283d3","user":{"login":"julien-f","id":298721,"avatar_url":"https://avatars.githubusercontent.com/u/298721?v=3","gravatar_id":"","url":"https://api.github.com/users/julien-f","html_url":"https://github.com/julien-f","followers_url":"https://api.github.com/users/julien-f/followers","following_url":"https://api.github.com/users/julien-f/following{/other_user}","gists_url":"https://api.github.com/users/julien-f/gists{/gist_id}","starred_url":"https://api.github.com/users/julien-f/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julien-f/subscriptions","organizations_url":"https://api.github.com/users/julien-f/orgs","repos_url":"https://api.github.com/users/julien-f/repos","events_url":"https://api.github.com/users/julien-f/events{/privacy}","received_events_url":"https://api.github.com/users/julien-f/received_events","type":"User","site_admin":false},"body":"`const pattern = patterns[field]`.","created_at":"2015-11-18T14:52:48Z","updated_at":"2015-11-18T14:52:48Z","html_url":"https://github.com/vatesfr/xo-server/pull/123#discussion_r45208086","pull_request_url":"https://api.github.com/repos/vatesfr/xo-server/pulls/123","_links":{"self":{"href":"https://api.github.com/repos/vatesfr/xo-server/pulls/comments/45208086"},"html":{"href":"https://github.com/vatesfr/xo-server/pull/123#discussion_r45208086"},"pull_request":{"href":"https://api.github.com/repos/vatesfr/xo-server/pulls/123"}}},"pull_request":{"url":"https://api.github.com/repos/vatesfr/xo-server/pulls/123","id":50615607,"html_url":"https://github.com/vatesfr/xo-server/pull/123","diff_url":"https://github.com/vatesfr/xo-server/pull/123.diff","patch_url":"https://github.com/vatesfr/xo-server/pull/123.patch","issue_url":"https://api.github.com/repos/vatesfr/xo-server/issues/123","number":123,"state":"open","locked":false,"title":"Logs CLI :","user":{"login":"Wescoeur","id":5610873,"avatar_url":"https://avatars.githubusercontent.com/u/5610873?v=3","gravatar_id":"","url":"https://api.github.com/users/Wescoeur","html_url":"https://github.com/Wescoeur","followers_url":"https://api.github.com/users/Wescoeur/followers","following_url":"https://api.github.com/users/Wescoeur/following{/other_user}","gists_url":"https://api.github.com/users/Wescoeur/gists{/gist_id}","starred_url":"https://api.github.com/users/Wescoeur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wescoeur/subscriptions","organizations_url":"https://api.github.com/users/Wescoeur/orgs","repos_url":"https://api.github.com/users/Wescoeur/repos","events_url":"https://api.github.com/users/Wescoeur/events{/privacy}","received_events_url":"https://api.github.com/users/Wescoeur/received_events","type":"User","site_admin":false},"body":"- Can print logs for one namespace or all namespaces\r\n- Can sort logs since one start timestamp/until one end timestamp\r\n- The sort results can be limited by one value","created_at":"2015-11-13T08:30:59Z","updated_at":"2015-11-18T14:52:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c377301f00f086a003bd834062b3a8cf22b6a9e6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/vatesfr/xo-server/pulls/123/commits","review_comments_url":"https://api.github.com/repos/vatesfr/xo-server/pulls/123/comments","review_comment_url":"https://api.github.com/repos/vatesfr/xo-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/vatesfr/xo-server/issues/123/comments","statuses_url":"https://api.github.com/repos/vatesfr/xo-server/statuses/448f24e33637ffc7846d6e0fbf0bdb1701b283d3","head":{"label":"vatesfr:abhamonr-logs-cli","ref":"abhamonr-logs-cli","sha":"448f24e33637ffc7846d6e0fbf0bdb1701b283d3","user":{"login":"vatesfr","id":2064170,"avatar_url":"https://avatars.githubusercontent.com/u/2064170?v=3","gravatar_id":"","url":"https://api.github.com/users/vatesfr","html_url":"https://github.com/vatesfr","followers_url":"https://api.github.com/users/vatesfr/followers","following_url":"https://api.github.com/users/vatesfr/following{/other_user}","gists_url":"https://api.github.com/users/vatesfr/gists{/gist_id}","starred_url":"https://api.github.com/users/vatesfr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vatesfr/subscriptions","organizations_url":"https://api.github.com/users/vatesfr/orgs","repos_url":"https://api.github.com/users/vatesfr/repos","events_url":"https://api.github.com/users/vatesfr/events{/privacy}","received_events_url":"https://api.github.com/users/vatesfr/received_events","type":"Organization","site_admin":false},"repo":{"id":7262203,"name":"xo-server","full_name":"vatesfr/xo-server","owner":{"login":"vatesfr","id":2064170,"avatar_url":"https://avatars.githubusercontent.com/u/2064170?v=3","gravatar_id":"","url":"https://api.github.com/users/vatesfr","html_url":"https://github.com/vatesfr","followers_url":"https://api.github.com/users/vatesfr/followers","following_url":"https://api.github.com/users/vatesfr/following{/other_user}","gists_url":"https://api.github.com/users/vatesfr/gists{/gist_id}","starred_url":"https://api.github.com/users/vatesfr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vatesfr/subscriptions","organizations_url":"https://api.github.com/users/vatesfr/orgs","repos_url":"https://api.github.com/users/vatesfr/repos","events_url":"https://api.github.com/users/vatesfr/events{/privacy}","received_events_url":"https://api.github.com/users/vatesfr/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/vatesfr/xo-server","description":"Server part of Xen Orchestra.","fork":false,"url":"https://api.github.com/repos/vatesfr/xo-server","forks_url":"https://api.github.com/repos/vatesfr/xo-server/forks","keys_url":"https://api.github.com/repos/vatesfr/xo-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vatesfr/xo-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vatesfr/xo-server/teams","hooks_url":"https://api.github.com/repos/vatesfr/xo-server/hooks","issue_events_url":"https://api.github.com/repos/vatesfr/xo-server/issues/events{/number}","events_url":"https://api.github.com/repos/vatesfr/xo-server/events","assignees_url":"https://api.github.com/repos/vatesfr/xo-server/assignees{/user}","branches_url":"https://api.github.com/repos/vatesfr/xo-server/branches{/branch}","tags_url":"https://api.github.com/repos/vatesfr/xo-server/tags","blobs_url":"https://api.github.com/repos/vatesfr/xo-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vatesfr/xo-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vatesfr/xo-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/vatesfr/xo-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vatesfr/xo-server/statuses/{sha}","languages_url":"https://api.github.com/repos/vatesfr/xo-server/languages","stargazers_url":"https://api.github.com/repos/vatesfr/xo-server/stargazers","contributors_url":"https://api.github.com/repos/vatesfr/xo-server/contributors","subscribers_url":"https://api.github.com/repos/vatesfr/xo-server/subscribers","subscription_url":"https://api.github.com/repos/vatesfr/xo-server/subscription","commits_url":"https://api.github.com/repos/vatesfr/xo-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/vatesfr/xo-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/vatesfr/xo-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/vatesfr/xo-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/vatesfr/xo-server/contents/{+path}","compare_url":"https://api.github.com/repos/vatesfr/xo-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vatesfr/xo-server/merges","archive_url":"https://api.github.com/repos/vatesfr/xo-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vatesfr/xo-server/downloads","issues_url":"https://api.github.com/repos/vatesfr/xo-server/issues{/number}","pulls_url":"https://api.github.com/repos/vatesfr/xo-server/pulls{/number}","milestones_url":"https://api.github.com/repos/vatesfr/xo-server/milestones{/number}","notifications_url":"https://api.github.com/repos/vatesfr/xo-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vatesfr/xo-server/labels{/name}","releases_url":"https://api.github.com/repos/vatesfr/xo-server/releases{/id}","created_at":"2012-12-20T18:23:37Z","updated_at":"2015-10-29T12:20:41Z","pushed_at":"2015-11-18T14:48:01Z","git_url":"git://github.com/vatesfr/xo-server.git","ssh_url":"git@github.com:vatesfr/xo-server.git","clone_url":"https://github.com/vatesfr/xo-server.git","svn_url":"https://github.com/vatesfr/xo-server","homepage":"","size":1684,"stargazers_count":44,"watchers_count":44,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":19,"forks":19,"open_issues":19,"watchers":44,"default_branch":"master"}},"base":{"label":"vatesfr:next-release","ref":"next-release","sha":"74e4b9d6d21685ee39d55352fae4504aa394dcd8","user":{"login":"vatesfr","id":2064170,"avatar_url":"https://avatars.githubusercontent.com/u/2064170?v=3","gravatar_id":"","url":"https://api.github.com/users/vatesfr","html_url":"https://github.com/vatesfr","followers_url":"https://api.github.com/users/vatesfr/followers","following_url":"https://api.github.com/users/vatesfr/following{/other_user}","gists_url":"https://api.github.com/users/vatesfr/gists{/gist_id}","starred_url":"https://api.github.com/users/vatesfr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vatesfr/subscriptions","organizations_url":"https://api.github.com/users/vatesfr/orgs","repos_url":"https://api.github.com/users/vatesfr/repos","events_url":"https://api.github.com/users/vatesfr/events{/privacy}","received_events_url":"https://api.github.com/users/vatesfr/received_events","type":"Organization","site_admin":false},"repo":{"id":7262203,"name":"xo-server","full_name":"vatesfr/xo-server","owner":{"login":"vatesfr","id":2064170,"avatar_url":"https://avatars.githubusercontent.com/u/2064170?v=3","gravatar_id":"","url":"https://api.github.com/users/vatesfr","html_url":"https://github.com/vatesfr","followers_url":"https://api.github.com/users/vatesfr/followers","following_url":"https://api.github.com/users/vatesfr/following{/other_user}","gists_url":"https://api.github.com/users/vatesfr/gists{/gist_id}","starred_url":"https://api.github.com/users/vatesfr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vatesfr/subscriptions","organizations_url":"https://api.github.com/users/vatesfr/orgs","repos_url":"https://api.github.com/users/vatesfr/repos","events_url":"https://api.github.com/users/vatesfr/events{/privacy}","received_events_url":"https://api.github.com/users/vatesfr/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/vatesfr/xo-server","description":"Server part of Xen Orchestra.","fork":false,"url":"https://api.github.com/repos/vatesfr/xo-server","forks_url":"https://api.github.com/repos/vatesfr/xo-server/forks","keys_url":"https://api.github.com/repos/vatesfr/xo-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vatesfr/xo-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vatesfr/xo-server/teams","hooks_url":"https://api.github.com/repos/vatesfr/xo-server/hooks","issue_events_url":"https://api.github.com/repos/vatesfr/xo-server/issues/events{/number}","events_url":"https://api.github.com/repos/vatesfr/xo-server/events","assignees_url":"https://api.github.com/repos/vatesfr/xo-server/assignees{/user}","branches_url":"https://api.github.com/repos/vatesfr/xo-server/branches{/branch}","tags_url":"https://api.github.com/repos/vatesfr/xo-server/tags","blobs_url":"https://api.github.com/repos/vatesfr/xo-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vatesfr/xo-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vatesfr/xo-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/vatesfr/xo-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vatesfr/xo-server/statuses/{sha}","languages_url":"https://api.github.com/repos/vatesfr/xo-server/languages","stargazers_url":"https://api.github.com/repos/vatesfr/xo-server/stargazers","contributors_url":"https://api.github.com/repos/vatesfr/xo-server/contributors","subscribers_url":"https://api.github.com/repos/vatesfr/xo-server/subscribers","subscription_url":"https://api.github.com/repos/vatesfr/xo-server/subscription","commits_url":"https://api.github.com/repos/vatesfr/xo-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/vatesfr/xo-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/vatesfr/xo-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/vatesfr/xo-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/vatesfr/xo-server/contents/{+path}","compare_url":"https://api.github.com/repos/vatesfr/xo-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vatesfr/xo-server/merges","archive_url":"https://api.github.com/repos/vatesfr/xo-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vatesfr/xo-server/downloads","issues_url":"https://api.github.com/repos/vatesfr/xo-server/issues{/number}","pulls_url":"https://api.github.com/repos/vatesfr/xo-server/pulls{/number}","milestones_url":"https://api.github.com/repos/vatesfr/xo-server/milestones{/number}","notifications_url":"https://api.github.com/repos/vatesfr/xo-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vatesfr/xo-server/labels{/name}","releases_url":"https://api.github.com/repos/vatesfr/xo-server/releases{/id}","created_at":"2012-12-20T18:23:37Z","updated_at":"2015-10-29T12:20:41Z","pushed_at":"2015-11-18T14:48:01Z","git_url":"git://github.com/vatesfr/xo-server.git","ssh_url":"git@github.com:vatesfr/xo-server.git","clone_url":"https://github.com/vatesfr/xo-server.git","svn_url":"https://github.com/vatesfr/xo-server","homepage":"","size":1684,"stargazers_count":44,"watchers_count":44,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":19,"forks":19,"open_issues":19,"watchers":44,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/vatesfr/xo-server/pulls/123"},"html":{"href":"https://github.com/vatesfr/xo-server/pull/123"},"issue":{"href":"https://api.github.com/repos/vatesfr/xo-server/issues/123"},"comments":{"href":"https://api.github.com/repos/vatesfr/xo-server/issues/123/comments"},"review_comments":{"href":"https://api.github.com/repos/vatesfr/xo-server/pulls/123/comments"},"review_comment":{"href":"https://api.github.com/repos/vatesfr/xo-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/vatesfr/xo-server/pulls/123/commits"},"statuses":{"href":"https://api.github.com/repos/vatesfr/xo-server/statuses/448f24e33637ffc7846d6e0fbf0bdb1701b283d3"}}}}