{"id":21743951,"url":"https://github.com/telefonica/node-express-logging","last_synced_at":"2025-04-13T05:07:09.133Z","repository":{"id":34137824,"uuid":"37972296","full_name":"Telefonica/node-express-logging","owner":"Telefonica","description":"Express middleware to log, using a configurable logger, each request and response.","archived":false,"fork":false,"pushed_at":"2019-11-06T18:38:56.000Z","size":24,"stargazers_count":16,"open_issues_count":1,"forks_count":6,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-13T05:06:59.414Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Telefonica.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-24T08:29:25.000Z","updated_at":"2023-02-06T15:50:23.000Z","dependencies_parsed_at":"2022-08-18T00:35:47.174Z","dependency_job_id":null,"html_url":"https://github.com/Telefonica/node-express-logging","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Telefonica%2Fnode-express-logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Telefonica%2Fnode-express-logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Telefonica%2Fnode-express-logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Telefonica%2Fnode-express-logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Telefonica","download_url":"https://codeload.github.com/Telefonica/node-express-logging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665747,"owners_count":21142123,"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-26T07:09:29.982Z","updated_at":"2025-04-13T05:07:09.113Z","avatar_url":"https://github.com/Telefonica.png","language":"JavaScript","readme":"# express-logging\n\nExpress middleware to log, using a configurable logger, each request and response.\n\n[![npm version](https://badge.fury.io/js/express-logging.svg)](http://badge.fury.io/js/express-logging)\n[![Build Status](https://travis-ci.org/telefonica/node-express-logging.svg)](https://travis-ci.org/telefonica/node-express-logging)\n[![Coverage Status](https://img.shields.io/coveralls/telefonica/node-express-logging.svg)](https://coveralls.io/r/telefonica/node-express-logging)\n\n## Installation\n\n```bash\nnpm install express-logging\n```\n\n## Basic usage\n\n```js\nvar express = require('express'),\n    expressLogging = require('express-logging'),\n    logger = require('logops');\n\nvar app = express();\napp.use(expressLogging(logger));\n\napp.listen(3000);\n```\n\n## Extended usage with options\n\nAn optional argument `options` can customize enhanced aspects for the logging. This argument is an object with the following elements:\n\n - `blacklist` is available to prevent some resources from being logged (for example, static resources). This argument is an array of strings. If the URL path starts with any of the elements of the blacklist array, then the logging of this request/response is ignored.\n - `policy` is a string to customize how the info is logged. It supports two values: `message` or `params`. The former serializes all the log entry into a single string message. The latter passes to the logger an object with the log entry parameters and a second argument with the message; this policy is useful in order to process these parameters by systems like logstash. The default value is `message`.\n\nThe following example would ignore any resource available at either `/images` or `/html`. It also activates the logging policy `params`.\n\n```js\nvar blacklist = ['/images', '/html'];\napp.use(expressLogging(logger, {blacklist: blacklist, policy: 'params'}));\n```\n\n## Logs\n\n### Logging with default policy **message**\n\nThe request is logged with:\n\n```js\nlogger.info('Request from %s: %s %s', clientIpAddress, requestMethod, requestUrl);\n```\n\nA response without `Location` header is logged with:\n\n```js\nlogger.info('Response with status %d in %d ms.', responseStatusCode, duration);\n```\n\nA response with `Location` header is logged with:\n\n```js\nlogger.info('Response with status %d in %d ms. Location: %s', responseStatusCode, duration, locationHeader);\n```\n\nBoth response log entries include the `duration` of the whole transaction (between receiving the request until replying with the response).\n\n### Logging with policy **params**\n\nThe request is logged with:\n\n```js\nvar params = {requestClientIp: requestClientIp, requestMethod: requestMethod, requestUrl: requestUrl};\nlogger.info(params, 'Request from %s: %s', requestMethod, requestUrl);\n```\n\nA response without `Location` header is logged with:\n\n```js\nvar params = {responseStatusCode: responseStatusCode, responseDuration: duration};\nlogger.info(params, 'Response with status %d', responseStatusCode);\n```\n\nA response with `Location` header is logged with:\n\n```js\nvar params = {responseStatusCode: responseStatusCode, responseDuration: duration, responseLocation: locationHeader};\nlogger.info(params, 'Response with status %d', responseStatusCode);\n```\n\nBoth response log entries include the `duration` of the whole transaction (between receiving the request until replying with the response).\n\n## License\n\nCopyright 2015, 2016 [Telefónica Investigación y Desarrollo, S.A.U](http://www.tid.es)\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelefonica%2Fnode-express-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftelefonica%2Fnode-express-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelefonica%2Fnode-express-logging/lists"}