{
  "name": "@mocks-server/logger",
  "version": "1.1.2",
  "description": "Namespaced logger",
  "keywords": [
    "log",
    "console",
    "traces",
    "namespace",
    "formatted"
  ],
  "author": "Javier Brea",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/mocks-server/main.git",
    "directory": "packages/logger"
  },
  "publishConfig": {
    "access": "public"
  },
  "files": [
    "dist"
  ],
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "dependencies": {
    "chalk": "4.1.1",
    "winston": "3.9.0",
    "winston-array-transport": "1.1.11"
  },
  "engines": {
    "node": ">=14.x"
  },
  "scripts": {
    "build": "tsc",
    "test:unit": "jest"
  },
  "readme": "<p align=\"center\">\n  <a href=\"https://github.com/mocks-server/main/actions?query=workflow%3Abuild+branch%3Amaster\"><img src=\"https://github.com/mocks-server/main/workflows/build/badge.svg?branch=master\" alt=\"Build Status\"></a>\n  <a href=\"https://codecov.io/gh/mocks-server/main\"><img src=\"https://codecov.io/gh/mocks-server/main/branch/master/graph/badge.svg?token=2S8ZR55AJV\" alt=\"Coverage\"></a>\n  <a href=\"https://sonarcloud.io/project/overview?id=mocks-server_main_logger\"><img src=\"https://sonarcloud.io/api/project_badges/measure?project=mocks-server_main_logger&metric=alert_status\" alt=\"Quality Gate\"></a>\n  <a href=\"https://www.npmjs.com/package/@mocks-server/logger\"><img src=\"https://img.shields.io/npm/dm/@mocks-server/logger.svg\" alt=\"Downloads\"></a>\n  <a href=\"https://renovatebot.com\"><img src=\"https://img.shields.io/badge/renovate-enabled-brightgreen.svg\" alt=\"Renovate\"></a>\n  <a href=\"https://github.com/mocks-server/main/blob/master/packages/logger/LICENSE\"><img src=\"https://img.shields.io/npm/l/@mocks-server/logger.svg\" alt=\"License\"></a>\n</p>\n\n---\n\n# Logger\n\n[Winston](https://github.com/winstonjs/winston)-based logger allowing to create nested namespaces. It provides:\n\n* Nested namespaces\n* Each namespace includes its \"path\" in the logs generated by it (the path is formed by its label appended to all its parent labels).\n* Coloured logs, with format: `HH:mm:ss:SS [level][...parentLabel:parentLabel:label?] message`\n* Store logs from each different namespace in a different array.\n* Store logs from all namespaces in a global store.\n* Each namespace log level can be set separately, and child namespaces can inherit the change or not.\n* Emit events whenever a log is added to any store.\n\n## Usage\n\nA brief example:\n\n```js\nconst { Logger } = require(\"@mocks-server/logger\");\n\n// Create root logger\nconst logger = new Logger();\n\nlogger.setLevel(\"debug\");\n\nlogger.info(\"Hello world\");\n// 18:41:43:16 [info] Hello world\n\nconst dbLogger = logger.namespace(\"db\");\n\ndbLogger.verbose(\"Hello from database component\");\n// 18:41:43:16 [verbose][db] Hello from database component\n\nconst dbConnectionLogger = dbLogger.namespace(\"connection\");\n\ndbConnectionLogger.debug(\"Connecting\");\n// 18:41:43:16 [debug][db:connection] Connecting\n\nconsole.log(dbConnectionLogger.store);\n/*\n[ '18:41:43:16 [debug][db:connection] Connecting' ]\n*/\n\nconsole.log(logger.globalStore);\n/*\n[\n  '18:41:43:16 [info] Hello world',\n  '18:41:43:16 [verbose][db] Hello from database component',\n  '18:41:43:16 [debug][db:connection] Connecting'\n]\n*/\n```\n\n## API\n\n### Logger constructor\n\n```js\nconst logger = new Logger();\n``` \n\n* __`Logger(label?, options?)`__. Returns a `logger` instance.\n  * __`label`__ _(String)_: Label for the root namespace. Optional.\n  * __`options`__ _(Object)_: Optional.\n    * __`level`__ _(String)_: - Initial level, can be one of `silent`, `error`, `warn`, `info`, `verbose`, `debug` or `silly`.\n    * __`storeLimit`__ _(Number)_: - Limit of logs to store in the root namespace `store` array. The option will be inherited by all children namespaces. Default is 1000.\n    * __`globalStoreLimit`__ _(Number)_: - Limit of logs to store in the global `store` array, which stores logs from all nested namespaces. Default is 1000.\n\n### logger instance\n\n* __`error(message)`__: The message will be logged always except if the current `level` is `silent`.\n* __`warn(message)`__: The message will be logged always except if the current `level` is `error` or `silent`.\n* __`info(message`__: The message will be logged whenever the current `level` is not `error`, `warn` or `silent`.\n* __`verbose(message)`__: The message will be logged whenever the current `level` is upper or equal than `verbose`.\n* __`debug(message)`__: The message will be logged whenever the current `level` is upper or equal than `debug`.\n* __`silly(message)`__: The message will be logged whenever the current `level` is upper or equal than `silly`.\n* __`setLevel(level, [options])`__: Sets the logger current log level for the current namespace and all children namespaces recursively.\n  * `level` _(String)_: Level can be one of `silent`, `error`, `warn`, `info`, `verbose`, `debug` or `silly`.\n  * `options` _(Object)_:\n    * `transport` _(String)_: The `Winston` transport in which the level has to be set. Can be one of `console` or `store`. If not provided, the level is set to all transports. In the root logger, changes in the `store` transport will be applied also to the `globalStore` transport.\n    * `propagate` _(Boolean)_: Propagates the level change to all children namespaces recursively or not. Default is `true`.\n    * `pinned` _(Boolean)_: When `true`, next level changes coming from propagations will be ignored and the transport/transports will keep the defined `level`. Default is `false`.\n    * `forcePropagation` _(Boolean)_: When `true`, the propagation will ignore `pinned` levels and will always override them.\n* __`namespace(label)`__: Creates and returns a new child namespace or returns an already existent one when the `label` already exists. The returned namespace has the same `Logger` methods described here. The created namespace will inherit the current namespace level.\n  * `label` _(String)_: Label for the new namespace. It will be displayed as part of the log `[label]`, appended to parent namespaces labels.\n* __`cleanStore()`__ Empties the namespace store array.\n* __`onChangeStore(callback)`__: Allows to add a listener that will be executed whenever a log is added to the current namespace store. __It returns a function that removes the listener once executed__.\n  * `callback()` _(Function)_: Callback to be executed.\n* __`onChangeGlobalStore(callback)`__: Allows to add a listener that will be executed whenever a log is added to the global store. __It returns a function that removes the listener once executed__.\n  * `callback()` _(Function)_: Callback to be executed.\n* __`store`__: Returns an array with logs stored in the current namespace.\n* __`globalStore`__: Returns an array with logs stored in all namespaces, including those from the ancestors. There is only one global namespace for each `Logger` instance, no matter the amount of namespaces it has.\n* __`label`__: Getter returning the namespace label.\n* __`level`__: Getter returning the current namespace level.\n* __`root`__: Getter returning the root namespace instance.\n"
}