{"id":13519564,"url":"https://github.com/tj/jog","last_synced_at":"2025-04-14T22:36:57.705Z","repository":{"id":2847442,"uuid":"3851323","full_name":"tj/jog","owner":"tj","description":"JSON document logging \u0026 filtering inspired by loggly for node.js","archived":false,"fork":false,"pushed_at":"2012-11-17T19:44:02.000Z","size":251,"stargazers_count":132,"open_issues_count":9,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-26T06:35:30.351Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://visionmedia.github.com/jog ","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tj.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-28T03:50:52.000Z","updated_at":"2023-08-20T19:34:35.000Z","dependencies_parsed_at":"2022-09-19T21:53:00.636Z","dependency_job_id":null,"html_url":"https://github.com/tj/jog","commit_stats":null,"previous_names":["visionmedia/jog"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fjog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fjog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fjog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fjog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tj","download_url":"https://codeload.github.com/tj/jog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248974660,"owners_count":21192186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T05:02:00.567Z","updated_at":"2025-04-14T22:36:57.683Z","avatar_url":"https://github.com/tj.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Stale"],"sub_categories":["JS Libraries \u0026 Utilities"],"readme":"\n# jog\n\n  JSON logging \u0026 reporting inspired by Loggly.\n\n## Installation\n\n    $ npm install jog\n\n## Features\n\n  - namespace support\n  - rich json documents\n  - log levels\n  - file store\n  - redis store\n  - document streaming\n  - tail -f like streaming\n  - CLI to tail and map / reduce logs\n\n## API\n\n### log.write(level, type[, obj])\n\n  Write to the logs:\n\n```js\nlog.write(level, type[, obj])\nlog.debug(type[, obj])\nlog.info(type[, obj])\nlog.warn(type[, obj])\nlog.error(type[, obj])\n```\n\n### log.ns(obj)\n\n  Namespace with the given `obj`, returning a new `Jog` instance\n  inheriting previous properties. You may call this several times\n  to produce more and more specific loggers.\n\n```js\nvar log = jog(new jog.FileStore('/tmp/log'));\n\n// log a user 5\nlog = log.ns({ uid: 5 });\n\n// log video id 99 for user 5\nlog = log.ns({ vid: 99 });\n\n// or both at once\nlog = log.ns({ uid: 5, vid: 99 });\n```\n\n### log.stream(options)\n\n  Return an `EventEmitter` emitting \"data\" and \"end\" events.\n\n   - `end` when __false__ streaming will not end\n   - `interval` the interval at which to poll (store-specific)\n\n### log.clear(callback)\n\n  Clear the logs and invoke the callback.\n\n## Example\n\n  Log random data using the `FileStore` and tail the file\n  for changes (typically in different processes). Jog will add\n  the `.level` and `.type` properties for you.\n\n```js\nvar jog = require('jog')\n  , log = jog(new jog.FileStore('/tmp/tail'))\n  , id = 0;\n\n// generate random log data\nfunction again() {\n  log.info('something happened', { id: ++id, user: 'Tobi' });\n  setTimeout(again, Math.random() * 100 | 0);\n}\n\nagain();\n\n// tail the json \"documents\"\nlog.stream({ end: false, interval: 500 })\n  .on('data', function(obj){\n    console.log(obj);\n  });\n```\n\nyields:\n\n```js\n{ id: 1,\n  level: 'info',\n  type: 'something happened',\n  timestamp: 1332907641734 }\n{ id: 2,\n  level: 'info',\n  type: 'something happened',\n  timestamp: 1332907641771 }\n...\n```\n\n## jog(1)\n\n```\n\n  Usage: jog [options]\n\n  Options:\n\n    -h, --help          output usage information\n    -V, --version       output the version number\n    -w, --within \u003cms\u003e   filter events to within the given \u003cms\u003e\n    -t, --type \u003cname\u003e   filter using the given type \u003cname\u003e\n    -l, --level \u003cname\u003e  filter using the given level \u003cname\u003e\n    -f, --ignore-eof    do not stop on EOF\n    -F, --file \u003cpath\u003e   load from the given \u003cpath\u003e\n    -R, --redis         load from redis store\n    -s, --select \u003cfn\u003e   use the given \u003cfn\u003e for filtering\n    -m, --map \u003cfn\u003e      use the given \u003cfn\u003e for mapping\n    -r, --reduce \u003cfn\u003e   use the given \u003cfn\u003e for reducing\n    -c, --color         color the output\n    -j, --json          output JSON (--color will not work)\n\n```\n\n### Examples\n\n  View all logs from tobi. The `_` object for the function\n  bodies of `--select` and `--map` represents the current\n  document, it's all just javascript.\n\n```\njog --file /tmp/jog --select \"_.user == 'tobi'\"\n[ { user: 'tobi',\n    duration: 1000,\n    level: 'info',\n    type: 'rendering video',\n    timestamp: 1332861272100 },\n  { user: 'tobi',\n    duration: 2000,\n    level: 'info',\n    type: 'compiling video',\n    timestamp: 1332861272100 },\n...\n```\n\n  Filter video compilation durations from \"tobi\" only:\n  \n```\n$ jog --file /var/log/videos.log --select \"_.user == 'tobi'\" --map _.duration\n[ 1000, 2000, 1200, 1000, 2000, 1200 ]\n```\n\n  Flags can be used several times:\n\n```\njog --file /var/log/videos.log --select \"_.vid \u003c 5\" --map _.type --map \"_.split(' ')\"\n[ [ 'compiling', 'video' ],\n  [ 'compiling', 'video' ],\n  [ 'compiling', 'video' ],\n  [ 'compiling', 'video' ] ]\n```\n\n  Tail errors only, with color:\n\n```\n$ jog --file my.log -f -c --select '_.level == \"error\"'\n{ level: 'error',\n  type: 'something broke',\n  timestamp: 1333943982669 }\n```\n\n  Display error messages within the last 10 seconds:\n\n```\n$ jog -F my.log --level error --select \"Date.now() - _.timestamp \u003c 10000\" --map _.type\n[ 'something broke', 'something broke', 'something broke' ]\n```\n\n  Events within the last 10 minutes, 5 seconds, and 200ms:\n\n```\n$ jog -F my.log --within 10m\n$ jog -F my.log --within 5s\n$ jog -F my.log --within 200\n```\n\n## Stores\n\n  By default Jog ships with the `FileStore` and `RedisStore`, however anything\n  with the following methods implemented will work:\n  \n    - `add(obj)` to add a log object\n    - `stream() =\u003e EventEmitter` to stream data\n    - `stream({ end: false }) =\u003e EventEmitter` to stream data indefinitely\n    - `clear(fn)` to clear the logs\n\n### FileStore(path)\n\n  Store logs on disk.\n\n```js\nvar jog = require('jog');\nvar log = jog(new jog.FileStore('/var/log/videos.log'));\n```\n\n### RedisStore([client])\n\n  Store logs in redis.\n\n```js\nvar jog = require('jog');\nvar log = jog(new jog.RedisStore);\n```\n\n## Performance\n\n  No profiling or optimizations yet but the `FileStore` can\n  stream back 250,000 documents (~21MB) in 1.2 seconds on my\n  macbook air.\n\n  The `RedisStore` with 250,000 documents streamed back\n  in 2.8 seconds on my air.\n\n## Running tests\n\n```\n$ npm install\n$ redis-server \u0026\n$ make test\n```\n\n## License \n\n(The MIT License)\n\nCopyright (c) 2012 LearnBoost \u0026lt;tj@learnboost.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fjog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftj%2Fjog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fjog/lists"}