{"id":21832180,"url":"https://github.com/pagarme/escriba","last_synced_at":"2026-01-29T09:38:17.167Z","repository":{"id":19763782,"uuid":"87779818","full_name":"pagarme/escriba","owner":"pagarme","description":":scroll: Logging on steroids","archived":false,"fork":false,"pushed_at":"2023-12-18T16:16:52.000Z","size":688,"stargazers_count":38,"open_issues_count":10,"forks_count":5,"subscribers_count":101,"default_branch":"master","last_synced_at":"2024-05-07T09:39:42.704Z","etag":null,"topics":["log4js","logger","logging","microservices","pagarme","winston"],"latest_commit_sha":null,"homepage":"","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/pagarme.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-10T07:25:17.000Z","updated_at":"2024-06-20T18:57:48.105Z","dependencies_parsed_at":"2023-12-18T18:44:19.567Z","dependency_job_id":null,"html_url":"https://github.com/pagarme/escriba","commit_stats":{"total_commits":93,"total_committers":17,"mean_commits":5.470588235294118,"dds":0.4301075268817204,"last_synced_commit":"5d91d07d3930662a5d392a865f23968fe3bc73b8"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pagarme%2Fescriba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pagarme%2Fescriba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pagarme%2Fescriba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pagarme%2Fescriba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pagarme","download_url":"https://codeload.github.com/pagarme/escriba/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230018547,"owners_count":18160431,"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":["log4js","logger","logging","microservices","pagarme","winston"],"created_at":"2024-11-27T19:18:23.962Z","updated_at":"2026-01-29T09:38:12.135Z","avatar_url":"https://github.com/pagarme.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Coverage Status](https://coveralls.io/repos/github/pagarme/escriba/badge.svg?branch=feature%2Fadd-coverage)](https://coveralls.io/github/pagarme/escriba?branch=feature%2Fadd-coverage)\n[![Build Status](https://travis-ci.org/pagarme/escriba.svg?branch=master)](https://travis-ci.org/pagarme/escriba)\n![Escriba Logo](https://image.ibb.co/jHdFD5/escriba.png)\n\n\u003e Logging on steroids\n\n# Escriba\n\nThe motivations for this library is to provide ways for a better express application logging. To achieve this goal we provide tools to managing logs, a log tracker across services and we add relevant information to your log.\n\n# Cool features\n\n- JSON format\n- Unique id\n- Request and responses share the same id. This enables tracking the path of a request across your services\n- Hide secret information based on regex\n- Adds extra information to your logs as `pid`, `hostname`, `level`, `startTime`, and `latency`\n- Filter props from request and/or response\n- Skip routes based on methods/rules/body props\n\n# Installation\n\n```sh\nnpm install --save escriba\n```\n\n# Usage\n\nEscriba provides two kinds of logger: `logger` and `httpLogger`.\n\n## Logger\n\nUse `logger` log across your application.\n\nFor example, to log some information from an `userController` hidding the password property:\n\n```js\nconst log4js = require('log4js').getLogger()\nconst escriba = require('escriba')\nconst cuid = require('cuid')\n\nlog4js.level = 'info'\n\nconst { logger } = escriba({\n  loggerEngine: log4js,\n  service: 'api',\n  sensitive: {\n    password: {\n      paths: ['message.password'],\n      pattern: /\\w.*/g,\n      replacer: '*'\n    }\n  }\n})\n\nlogger.info({ text: 'Setting user permission', password: 'abc' }, { id: cuid(), from: 'userController' })\n```\n\n## Http logger\n\nUse `httpLogger` to log an http request and response.\n\nFor this example we'll long only some properties: `id`, `body` and `statusCode`.\n\nWe'll also skip status route, options method and body property from routes that end with .csv or .xlsx.\n\nIt's important to hide sentive information like api_key.\n\n```js\nconst express = require('express')\nconst log4js = require('log4js').getLogger()\nconst escriba = require('escriba')\nconst cuid = require('cuid')\nconst roomController = require('./controllers/room')\n\nconst app = express()\n\nconst { httpLogger } = escriba({\n  loggerEngine: log4js,\n  sensitive: {\n    password: {\n      paths: ['body.api_key'],\n      pattern: /(ak_test|ak_live).*/g,\n      replacer: '*'\n    }\n  },\n  httpConf: {\n    logIdPath: 'headers.my_path_id',\n    propsToLog: {\n      request: ['id', 'url', 'body'],\n      response: ['id', 'url', 'body', 'statusCode', 'latency']\n    },\n    envToLog: ['SHELL', 'PATH'],\n    skipRules: [\n      {\n        route: /\\/status/,\n        method: /.*/,\n        onlyBody: false\n      },\n      {\n        route: /.*\\.(csv|xlsx)$/,\n        method: /GET/,\n        onlyBody: true\n      },\n      {\n        route: /.*/,\n        method: /OPTIONS/,\n        onlyBody: false\n      }\n    ],\n    propMaxLength: {\n      body: 2048,\n      url: 1024\n    },\n    propsToParse: {\n      request: {\n         'id': String,\n         'body.document_number': Number,\n      },\n      response: {\n         'body.customer.id': Number\n      }\n    }\n  }\n})\n\napp.use(httpLogger)\n\napp.get('/room/:id', roomController.index)\napp.post('/room', roomController.save)\n```\n\nEvery request and response will be logged, and the coolest part: both will have the same id. This is important because you can search for this id and get all information about your request and response.\n\nAs you can see we have the logIdPath inside the httpConf object. This property allow you to pick log id from a desired path in request object. If you don't pass this property escriba will generate a new id for your request/response logs using cuid.\n\nThis id is injected in the `req` object, so if you need to log some extra information between a request and response just do something like this:\n\n```js\nlogger.info('some controller information', { id: req.id })\n```\n\nAlso it's possible to skip logs or only the body property through skipRules, in the example we are skiping logs from route `/status` for `all methods` and skiping the `body` property from routes that ends with `.csv` or `.xlsx`.\n\nThe `propMaxLength` attribute is responsible to limit the number of characters for certain properties if they exist within `propsTolog` definition.\n\nThe `propsToParse` attribute is responsible to parse any atribute based on a path, the parsing works by providing a valid javascript native Function (e.g String, Number etc).\n\n## Masks\n\nJust like the `loggerEngine` option, `escriba` accepts two types of mask engines, they are [iron-mask](https://www.npmjs.com/package/iron-mask) and [mask-json](https://www.npmjs.com/package/mask-json). If you don't pass any `maskEngine`, `iron-mask` will be used as default.\n\n### iron-mask\n```javascript\nconst { logger, httpLogger } = escriba({\n  loggerEngine,\n  service: 'bla',\n  // no `maskEngine` informed, `iron-mask` will be used\n  sensitive: { // `iron-mask` sensitive format\n    secret: {\n      paths: ['message.secret', 'message.metadata.secret', 'body.secret'],\n      pattern: /\\w.*/g,\n      replacer: '*',\n    },\n  },\n})\n```\n\n### mask-json\n```javascript\nconst maskJson = require('mask-json')\nconst { logger, httpLogger } = escriba({\n  loggerEngine,\n  service: 'bla',\n  maskEngine: maskJson,\n  sensitive: { // `mask-json` sensitive format\n    blacklist: ['secret'],\n    options: {\n      replacement: '*',\n    },\n  },\n})\n```\n\n## Integrations\nYou can enable integrations by simply passing a `integrations` key in the config. Like this:\n```javascript\nescriba({\n  integrations: {\n    datadog: true\n  }\n})\n```\n\nBut remember, for each integration to work you may need to configure your application via environment variables.\n\n### Datadog\nYou'll need to install `dd-trace` in your application.\nThe Datadog integration enable this feature: https://docs.datadoghq.com/tracing/advanced/connect_logs_and_traces/.\n\n## Examples\n\nThe `log-generator` inside `examples` folder will run a Node.js application that will make a request for itself every in an interval defined by the user (in milliseconds). The application will get input values from an environment variable `ESCRIBA_TIMEOUT`(3000 is the default value, this represents 3 seconds)\n\nTo use `log-generator` through Docker use these commands inside the `log-generator` folder:\n\n```\ndocker build -t pagarme/log-generator:latest .\n\ndocker run -e ESCRIBA_TIMEOUT=3000 -p 3000:3000 -d -v $(cd ../../ \u0026\u0026 pwd):/log-generator/node_modules/escriba pagarme/log-generator:latest\n\n```\n\nAnd to make some manual requests use:\n\n```\ncurl -H \"Content-Type: application/json\" -X GET http://localhost:3000/escriba\n\ncurl -H \"Content-Type: application/json\" -X POST -d '{\"username\":\"a name\"}' http://localhost:3000/escriba\n```\n\nThe `log-generator` example will get Escriba library from npm. If you want to get the library directly from the repository run docker with `-v`:\n\n```\ndocker run -e ESCRIBA_TIMEOUT=3000 -p 3000:3000 -d -v $(cd ../../ \u0026\u0026 pwd):/escriba pagarme/log-generator:latest\n```\n\n## License\n\n```\nThe MIT License (MIT)\nCopyright (c) 2017 Pagar.me Pagamentos S/A\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpagarme%2Fescriba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpagarme%2Fescriba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpagarme%2Fescriba/lists"}