{"id":21491622,"url":"https://github.com/mac-/hapi-logger","last_synced_at":"2025-07-15T17:32:32.624Z","repository":{"id":19862506,"uuid":"23125829","full_name":"mac-/hapi-logger","owner":"mac-","description":"A Hapi plugin for writing logs via bunyan","archived":false,"fork":false,"pushed_at":"2017-08-07T04:02:20.000Z","size":38,"stargazers_count":5,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-20T04:32:14.573Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mac-.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":"2014-08-19T21:04:56.000Z","updated_at":"2017-06-17T16:12:39.000Z","dependencies_parsed_at":"2022-08-25T23:30:42.372Z","dependency_job_id":null,"html_url":"https://github.com/mac-/hapi-logger","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mac-%2Fhapi-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mac-%2Fhapi-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mac-%2Fhapi-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mac-%2Fhapi-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mac-","download_url":"https://codeload.github.com/mac-/hapi-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226057477,"owners_count":17566955,"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-11-23T15:17:09.031Z","updated_at":"2024-11-23T15:17:09.736Z","avatar_url":"https://github.com/mac-.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hapi-logger\n\n[![Build Status](https://secure.travis-ci.org/mac-/hapi-logger.png)](http://travis-ci.org/mac-/hapi-logger)\n[![Coverage Status](https://coveralls.io/repos/mac-/hapi-logger/badge.png)](https://coveralls.io/r/mac-/hapi-logger)\n[![Code Climate](https://codeclimate.com/github/mac-/hapi-logger.png)](https://codeclimate.com/github/mac-/hapi-logger)\n[![NPM version](https://badge.fury.io/js/hapi-logger.png)](http://badge.fury.io/js/hapi-logger)\n[![Dependency Status](https://david-dm.org/mac-/hapi-logger.png)](https://david-dm.org/mac-/hapi-logger)\n\n[![NPM](https://nodei.co/npm/hapi-logger.png?downloads=true\u0026stars=true)](https://nodei.co/npm/hapi-logger/)\n\n\u003e A Hapi plugin for writing logs to stdout via bunyan\n\nBunyan is a great module for logging, but I like the flexibility that having tagged log messages gives me over your traditional log levels. Luckily Hapi already emits log events with tags, so we can add those tags to our log message. The current implementation of this module logs every message as \"info\" as far as bunyan is concerned, so you might as well ignore the \"level\" property on the log message. However, all the tags are included on the message, which should give enough context about the message.\n\n## Contributing\n\nThis module makes use of a `Makefile` for building/testing purposes. After obtaining a copy of the repo, run the following commands to make sure everything is in working condition before you start your work:\n\n\tmake install\n\tmake test\n\nBefore committing a change to your fork/branch, run the following commands to make sure nothing is broken:\n\n\tmake test\n\tmake test-cov\n\nDon't forget to bump the version in the `package.json` using the [semver](http://semver.org/spec/v2.0.0.html) spec as a guide for which part to bump. Submit a pull request when your work is complete.\n\n***Notes:***\n* Please do your best to ensure the code coverage does not drop. If new unit tests are required to maintain the same level of coverage, please include those in your pull request.\n* Please follow the same coding/formatting practices that have been established in the module.\n\n## Installation\n\n\tnpm install hapi-logger\n\n## Usage\n\nTo install this plugin on your Hapi server, do something similar to this:\n\n```js\nvar Hapi = require('hapi');\nvar server = new Hapi.Server();\n\nvar hapiLoggerConfig = {};\n\nserver.register({ register: require('hapi-logger'), options: hapiLoggerConfig }, function(err) {\n\tif (err) {\n\t\tconsole.log('error', 'Failed loading plugin: hapi-logger');\n\t}\n});\n```\n\n## Plugin Options\n\n### `name`\n\nThe name of your application, or any other name you wish to have contained within your log message, for this pack of servers. Defaults to `'hapi-logger'`\n\n### `src`\n\nA flag that tells bunyan whether or not to include the location from where the log message originiated. Don't set this to `true` in production! Defaults to `false`\n\n### `tags`\n\nThe tags used to determine when a log message is logged. This value can contain both strings and arrays of strings. The items in the top level of the collection are OR'd, while any items in nested arrays are AND'd. \n\nIf the collection includes `'*'` then all messages will be logged. Defaults to `['*']`\n\n#### Examples\n\n1. Top-level strings only:\n\n```js\n[\n\t'error',\n\t'info'\n]\n```\n\nMeans that log messages with either the tag `'error'` OR `'info'` will get logged.\n\n2. Nested strings only:\n\n```js\n[\n\t[\n\t\t'error',\n\t\t'request'\n\t]\n]\n```\n\nMeans that log messages with the tags `'error'` AND `'request'` will get logged.\n\n3. Top-level and nested strings:\n\n```js\n[\n\t'info',\n\t[\n\t\t'error',\n\t\t'request'\n\t]\n]\n```\n\nMeans that log messages with either the tag `'info'`  OR the tags `'error'` AND `'request'` will get logged.\n\n### `ignoredTags`\n\nThe tags used to determine when a log message is NOT logged. This value can contain both strings and arrays of strings. The items in the top level of the collection are OR'd, while any items in nested arrays are AND'd.\n\nIf the collection includes `'*'` then no messages will be logged. Defaults to `[]`\n\n**Note:** If a log message matches any of these tags, it will not be logged, even if it would have been because it matched values in `tags`.\n\n#### Examples\n\n1. Top-level strings only:\n\n```js\n[\n\t'error',\n\t'info'\n]\n```\n\nMeans that log messages with either the tag `'error'` OR `'info'` will not get logged.\n\n2. Nested strings only:\n\n```js\n[\n\t[\n\t\t'error',\n\t\t'request'\n\t]\n]\n```\n\nMeans that log messages with the tags `'error'` AND `'request'` will not get logged.\n\n3. Top-level and nested strings:\n\n```js\n[\n\t'info',\n\t[\n\t\t'error',\n\t\t'request'\n\t]\n]\n```\n\nMeans that log messages with either the tag `'info'`  OR the tags `'error'` AND `'request'` will not get logged.\n\n### `shouldLog`\n\nA function that will receive the log data as a parameter and should return `true` if the message should be logged, or `false` if the message should not be logged. The `tags` and `ignoredTags` are evaulated first then this function will be executed. Defaults to `null`\n\n## Example\n\nA Hapi route configured like this:\n\n```js\nserver.route({\n\tmethod: 'GET',\n\tpath: '/test/{param}',\n\thandler: function(request, reply) {\n\t\trequest.log(['get', 'testResource'], 'Some important info...');\n\t\treply('Success!');\n\t}\n});\n```\n\nwould cause the following log message to be written (in addition to any other internal Hapi-related events) when a request is issued to the route:\n\n```\n{\"name\":\"hapi-logger\",\"hostname\":\"Me\",\"pid\":54705,\"level\":30,\"tags\":[\"get\",\"testResource\"],\"req\":{\"id\":\"1408481983531-54705-47711\",\"headers\":{\"user-agent\":\"curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5\",\"host\":\"localhost:8080\",\"accept\":\"*/*\"},\"method\":\"get\",\"info\":{\"received\":1408481983531,\"remoteAddress\":\"127.0.0.1\",\"remotePort\":63014,\"referrer\":\"\",\"host\":\"localhost:8080\"},\"path\":\"/test/1234\"},\"msg\":\"Some important info...\",\"time\":\"2014-08-19T20:59:43.542Z\",\"v\":0}\n```\n\nIn addition to user-initiated request log events, this module will also listen for server `log` events, `request` events, and `internalError` events, and log those if not filtered by the configured `tags` or `ignoredTags`.\n\nTo provide a little more context about a log message, you can log messages like so:\n\n```js\nserver.log(['mytag'], { message: 'My log message', other: 'Some other data' });\n```\n\nBy passing an object as the second paramter, you can pass along context with your message. If no message is detected a default message will be used. Here are the default messages for the corresponding Hapi events:\n\n* `log`: \"Hapi Server Log\"\n* `request`: \"Hapi Server Request Log\"\n\nIf an `internalError` event is received, then the log message will be the error message.\n\n## Version Compatibility\n\n### Currently compatible with: Hapi 16.x.x\n\n* 0.1.x - Hapi 6.x.x\n* 0.2.x - Hapi 7.x.x\n* 0.3.x - Hapi 8.x.x\n* 0.4.x - Hapi 11.x.x\n* 1.0.x - Hapi 16.x.x\n* 2.0.x - Hapi 16.x.x\n\n# License\n\nThe MIT License (MIT)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmac-%2Fhapi-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmac-%2Fhapi-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmac-%2Fhapi-logger/lists"}