{"id":18234110,"url":"https://github.com/smartprix/oak","last_synced_at":"2025-04-03T21:30:19.581Z","repository":{"id":57161154,"uuid":"154533139","full_name":"smartprix/oak","owner":"smartprix","description":"A simple logger that writes to json file, console, or both","archived":false,"fork":false,"pushed_at":"2024-03-18T12:21:54.000Z","size":233,"stargazers_count":4,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-19T17:03:29.567Z","etag":null,"topics":["error-parsing","filelogger","js","json","logging","node","oak","pretty-logger"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@smpx/oak","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smartprix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-24T16:26:34.000Z","updated_at":"2024-03-18T11:30:59.000Z","dependencies_parsed_at":"2022-08-27T09:22:26.564Z","dependency_job_id":null,"html_url":"https://github.com/smartprix/oak","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartprix%2Foak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartprix%2Foak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartprix%2Foak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartprix%2Foak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smartprix","download_url":"https://codeload.github.com/smartprix/oak/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247082729,"owners_count":20880709,"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":["error-parsing","filelogger","js","json","logging","node","oak","pretty-logger"],"created_at":"2024-11-04T17:03:43.316Z","updated_at":"2025-04-03T21:30:19.253Z","avatar_url":"https://github.com/smartprix.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://travis-ci.com/smartprix/oak\"\u003e\u003cimg src=\"https://travis-ci.com/smartprix/oak.svg?branch=master\" alt=\"Travis\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@smpx/oak\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@smpx/oak.svg\" alt=\"Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@smpx/oak\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@smpx/oak.svg\" alt=\"Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@smpx/oak\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/@smpx/oak.svg\" alt=\"License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://david-dm.org/smartprix/oak\"\u003e\u003cimg src=\"https://david-dm.org/smartprix/oak/status.svg\" alt=\"Dependencies\"\u003e\u003c/a\u003e\n\u003ca href=\"https://david-dm.org/smartprix/oak?type=dev\"\u003e\u003cimg src=\"https://david-dm.org/smartprix/oak/dev-status.svg\" alt=\"Dev Dependencies\"\u003e\u003c/a\u003e\n\n\n# oak\nA simple logger that writes to json file, console, or any other custom transport.\n\n### Install\n\n\tyarn add @smpx/oak\n  \n### Use\n\n```js\n// You can also use default import\nimport {Oak} from '@smpx/oak';\n\nOak.log('This is a simple message');\n\n// The first argument is special, if it is a plain object it will be parsed and\n// properties will be displayed seperate from the message.\n// Some special properties are duration, label, level, error (an object itself), duration, createdAt\nOak.info({label: 'Apply a label'}, 'You can', 'Chain', 'Like in console', 0, 'Other types than string too');\n```\n\n##### Preview:\n![Simple logs](./docs/simple.png)\n\n\n#### Timers\n\n```js\nOak.time('Unique message');\n\nOak.timeEnd('Unique message', 'Extra info', 'just like in Oak.log');\n\n// Alternative timers\n\nconst key = Oak.time();\n\nOak.timeEnd(key, 'Extra info', 'just like in Oak.log');\n```\n\n##### Preview:\n![Time Functions](./docs/time.png)\n\n```js\n// Function to time\nasync function fnToTime() {\n\treturn new Promise(resolve =\u003e setTimeout(resolve, 3000));\n}\n\n// Time functions (Returns a promise)\n\n// The last argument needs to be the function to time\nOak.logTimeTaken(fnToTime);\n\nOak.logTimeTaken({label: 'Timer'}, 'Just like', 'Oak.log', fnToTime);\n```\n\n##### Preview:\n![Time functions](./docs/functionTime.png)\n\n#### Create Instances\n\n```js\nimport {Oak} from '@smpx/oak';\n\nconst oak = new Oak('instanceLabel');\n\n// This instance will have the label set to 'instanceLabel' automatically.\noak.log('Test');\n\n\nconst oak2 = new Oak({label: 'new', info: 'This is instance oak2'});\n\noak2.warn('Extra info will be attached');\n```\n\n##### Preview:\n![Instances with preset options](./docs/instance.png)\n\n#### Error parsing\n\n```js\nimport {Oak} from '@smpx/oak';\n\nOak.error('Message for understanding context', new Error('Error Message'));\n```\n\n##### Preview:\n![Error Parsing](./docs/error.png)\n\n### Install Exception Handlers and Process Exit Handlers\n\n```js\nimport {Oak} from '@smpx/oak';\n\nOak.installExceptionHandlers();\nOak.installExitHandlers();\n\n```\n##### Preview:\n![Exit handlers](./docs/exit.png)\n\n\n### Transports\n\nBy default Oak comes with the ConsoleLogs transport set. A FileLogs transport is also included.\nThe transports are global for now, feel free to open a PR that adds an option to set instance level transports.\n\nTo use it do:\n\n```js\nimport {Oak, FileLogs} from '@smpx/oak';\n\nOak.setTransports([new FileLogs({path: 'path/to/folder/for/logs', table: 'filename/for/logs'})])\n\n```\n\nIt uses the [rotating-file-stream](https://github.com/iccicci/rotating-file-stream#readme) module behind the scenes and saves each log object in json logs. They are rotated every day and kept for 10 days.\n\n\nYou can build your own custom transport, we have a `BasicLogs` transport that you can import and extend. Just implement a simple log function, that is all that's needed.\n\n```js\nimport {Oak, BasicLogs} from '@smpx/oak'\n\nclass CustomTransport extends BasicLogs {\n\tlog(info) {\n\t\t// info is an object, with all the properties set in global options, any options passed to log function, 'level', 'message', 'label', and 'duration' (if using time functions) properties.\n\t\tconsole.log(info);\n\t}\n}\n\n```\n\n### oak-viewer CLI\n\nA simple CLI to stream logs saved by FileLogs transport. This is more of a custom implentation for our needs, with properties highlighted that we have set in global options.\n\n```\nUsage: oak-viewer [app] [options]\n\nView logs generated by oak's FileLogs in awesome formatting\nExamples:\noak-viewer --err --lines=100\noak-viewer sm-crawler --level=warn,err --label=knex,koa\noak-viewer --grep=NotFoundError,InternalServerError\n\nTo negate a condition you can prepend the value with ~\nExamples:\noak-viewer --level=~silly --label=~maxmind,~jsonld\noak-viewer ~list-crawler --level=err --grep=~NotFoundError\n\n\nOptions:\n  -v, --version            output the version number\n  -p, --path [dir]         Path given to filelogs (default is logs folder in root dir)\n  --file, --table [table]  Table option given to FileLogs (default is 'log')\n  -d, --date [date]        Date for which to view logs [format: YYYY-MM-DD]\n  --err, --error           Only show errors\n  --lines [lines]          Show this many previous lines (default 10)\n  --level [levels]         Only show these levels, --levels=info,err\n  --label [labels]         Only show these labels, --labels=knex,koa\n  --grep [regex]           Only show logs matching this regex, --grep=NotFoundError\n  --fields [fields]        Only show these fields in a log message, --fields=level,ctx.url\n  --match [match_regexes]  Advanced per field based filtering, --match=\"ctx.url:some_regex,sql:some_regex\"\n  -h, --help               output usage information\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartprix%2Foak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartprix%2Foak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartprix%2Foak/lists"}