{"id":28454957,"url":"https://github.com/inversify/inversify-logger-middleware","last_synced_at":"2025-06-28T16:32:20.314Z","repository":{"id":8564756,"uuid":"58493653","full_name":"inversify/inversify-logger-middleware","owner":"inversify","description":"A basic logger middleware for InversifyJS","archived":false,"fork":false,"pushed_at":"2022-03-14T11:05:19.000Z","size":286,"stargazers_count":26,"open_issues_count":10,"forks_count":10,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-06-03T16:06:14.791Z","etag":null,"topics":["dependency-injection","express","inversifyjs","inversifyjs-devtools","inversifyjs-middleware","logger-middleware","logging","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/inversify.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":"2016-05-10T21:07:24.000Z","updated_at":"2024-12-12T13:13:39.000Z","dependencies_parsed_at":"2022-08-07T04:16:38.165Z","dependency_job_id":null,"html_url":"https://github.com/inversify/inversify-logger-middleware","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/inversify/inversify-logger-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-logger-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-logger-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-logger-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-logger-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inversify","download_url":"https://codeload.github.com/inversify/inversify-logger-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inversify%2Finversify-logger-middleware/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259756912,"owners_count":22906682,"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":["dependency-injection","express","inversifyjs","inversifyjs-devtools","inversifyjs-middleware","logger-middleware","logging","nodejs"],"created_at":"2025-06-06T21:14:24.967Z","updated_at":"2025-06-28T16:32:20.309Z","avatar_url":"https://github.com/inversify.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# inversify-logger-middleware\n\n[![Join the chat at https://gitter.im/inversify/InversifyJS](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/inversify/InversifyJS?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Build Status](https://secure.travis-ci.org/inversify/inversify-logger-middleware.svg?branch=master)](https://travis-ci.org/inversify/inversify-logger-middleware)\n[![Test Coverage](https://codeclimate.com/github/inversify/inversify-logger-middleware/badges/coverage.svg)](https://codeclimate.com/github/inversify/inversify-logger-middleware/coverage)\n[![npm version](https://badge.fury.io/js/inversify-logger-middleware.svg)](http://badge.fury.io/js/inversify-logger-middleware)\n[![Dependencies](https://david-dm.org/inversify/inversify-logger-middleware.svg)](https://david-dm.org/inversify/inversify-logger-middleware#info=dependencies)\n[![img](https://david-dm.org/inversify/inversify-logger-middleware/dev-status.svg)](https://david-dm.org/inversify/inversify-logger-middleware/#info=devDependencies)\n[![img](https://david-dm.org/inversify/inversify-logger-middleware/peer-status.svg)](https://david-dm.org/inversify/inversify-logger-middleware/#info=peerDependenciess)\n[![Known Vulnerabilities](https://snyk.io/test/github/inversify/inversify-logger-middleware/badge.svg)](https://snyk.io/test/github/inversify/inversify-logger-middleware)\n\n[![NPM](https://nodei.co/npm/inversify-logger-middleware.png?downloads=true\u0026downloadRank=true)](https://nodei.co/npm/inversify-logger-middleware/)\n[![NPM](https://nodei.co/npm-dl/inversify-logger-middleware.png?months=9\u0026height=3)](https://nodei.co/npm/inversify-logger-middleware/)\n\nA console logger middleware for [InversifyJS](https://github.com/inversify/InversifyJS).\n\n![](http://i.imgur.com/iFAogro.png)\n\n## Installation\n\nYou can install `inversify-logger-middleware` using npm:\n\n```sh\nnpm install inversify inversify-logger-middleware reflect-metadata --save\n```\n\nThe `inversify-logger-middleware` type definitions are included in the npm module and require TypeScript 2.0.\nPlease refer to the [InversifyJS documentation](https://github.com/inversify/InversifyJS#installation) to learn more about the installation process.\n\n### Motivation\n\nLets imagine that we have already configured an InversifyJS Container and the logger middleware using the fillowing bindings:\n\n```ts\nlet module = new ContainerModule((bind: inversify.interfaces.Bind) =\u003e {\n    bind\u003cWeapon\u003e(\"Weapon\").to(Katana).whenInjectedInto(Samurai);\n    bind\u003cWeapon\u003e(\"Weapon\").to(Shuriken).whenInjectedInto(Ninja);\n    bind\u003cWarrior\u003e(\"Warrior\").to(Samurai).whenTargetTagged(\"canSneak\", false);\n    bind\u003cWarrior\u003e(\"Warrior\").to(Ninja).whenTargetTagged(\"canSneak\", true);\n});\n```\n\nThis middleware will display the InversifyJS resolution plan in console in the following format.\n\n```ts\n//  container.getTagged\u003cWarrior\u003e(\"Warrior\", \"canSneak\", true);\n\nSUCCESS: 0.41 ms.\n    └── Request : 0\n        └── serviceIdentifier : Warrior\n        └── bindings\n            └── Binding\u003cWarrior\u003e : 0\n                └── type : Instance\n                └── implementationType : Ninja\n                └── scope : Transient\n        └── target\n            └── serviceIdentifier : Warrior\n            └── name : undefined\n            └── metadata\n                └── Metadata : 0\n                    └── key : canSneak\n                    └── value : true\n        └── childRequests\n            └── Request : 0\n                └── serviceIdentifier : Weapon\n                └── bindings\n                    └── Binding\u003cWeapon\u003e : 0\n                        └── type : Instance\n                        └── implementationType : Shuriken\n                        └── scope : Transient\n                └── target\n                    └── serviceIdentifier : Weapon\n                    └── name : shuriken\n                    └── metadata\n                        └── Metadata : 0\n                            └── key : name\n                            └── value : shuriken\n                        └── Metadata : 1\n                            └── key : inject\n                            └── value : Weapon\n```\n\nYou can configure which elements of the resolution plan are being displayed.\n\nThis kind of information can help you during the development of applications with InersifyJS.\n\n### Default settings and renderer\n\nYou can create a logger using the default settings as follows:\n\n```ts\nimport { makeLoggerMiddleware } from 'inversify-logger-middleware';\nlet logger = makeLoggerMiddleware();\n```\n\nThe default options are the following:\n\n```ts\nlet deatultOptions: LoggerSettings = {\n    request: {\n        bindings: {\n            activated: false,\n            cache: false,\n            constraint: false,\n            dynamicValue: false,\n            factory: false,\n            implementationType: true,\n            onActivation: false,\n            provider: false,\n            scope: false,\n            serviceIdentifier: false,\n            type: false\n        },\n        serviceIdentifier: true,\n        target: {\n            metadata: true,\n            name: false,\n            serviceIdentifier: false\n        }\n    },\n    time: true\n};\n```\n\nYou can use the option to determine which elements of the resolution plan should be logged.\n\nThe default renderer look as follows:\n\n```ts\nfunction consoleRenderer(out: string) {\n    console.log(out);\n}\n```\n\n### Custom settings and renderer\n\nThe following code snippet uses custom settings and a string renderer instead of the default console renderer.\n\n```ts\nlet options: LoggerSettings = {\n    request: {\n        serviceIdentifier: true,\n        bindings: {\n            scope: true\n        },\n        result: true\n    }\n};\n\n// Takes object (loggerOutput) instead of primitive (string) to share reference\nlet makeStringRenderer = function (loggerOutput: { content: string }) {\n    return function (out: string) {\n        loggerOutput.content = out;\n    };\n};\n\n\nlet loggerOutput = { content : \"\" };\nlet stringRenderer = makeStringRenderer(loggerOutput);\nlet logger = makeLoggerMiddleware(null, stringRenderer);\n```\n\n### Applying the middleware\n\nYou can apply the logger middlerare using the InversifyJS API:\n\n```ts\nlet container = new Container();\nlet logger = makeLoggerMiddleware();\ncontainer.applyMiddleware(logger);\n```\n\nPlease refere to the\n[InversifyJS documentation](https://github.com/inversify/InversifyJS#middleware)\nto learn more about middleware.\n\n### Demo app\n\nA sample application can be found at the\n[inversify-code-samples](https://github.com/inversify/inversify-code-samples/tree/master/inversify-binding-decorators) repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finversify%2Finversify-logger-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finversify%2Finversify-logger-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finversify%2Finversify-logger-middleware/lists"}