{"id":22374846,"url":"https://github.com/qubitproducts/driftwood","last_synced_at":"2025-07-30T22:31:24.105Z","repository":{"id":57216304,"uuid":"57292453","full_name":"QubitProducts/driftwood","owner":"QubitProducts","description":"A namespaced stylish logger","archived":false,"fork":false,"pushed_at":"2019-01-22T17:00:20.000Z","size":94,"stargazers_count":6,"open_issues_count":3,"forks_count":3,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-11-14T09:59:22.694Z","etag":null,"topics":["ceh","cmh","implement"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/QubitProducts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-28T10:18:43.000Z","updated_at":"2023-06-02T12:06:32.000Z","dependencies_parsed_at":"2022-08-26T15:01:15.018Z","dependency_job_id":null,"html_url":"https://github.com/QubitProducts/driftwood","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QubitProducts%2Fdriftwood","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QubitProducts%2Fdriftwood/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QubitProducts%2Fdriftwood/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QubitProducts%2Fdriftwood/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/QubitProducts","download_url":"https://codeload.github.com/QubitProducts/driftwood/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228192272,"owners_count":17882761,"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":["ceh","cmh","implement"],"created_at":"2024-12-04T21:18:43.586Z","updated_at":"2024-12-04T21:18:44.246Z","avatar_url":"https://github.com/QubitProducts.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# logger [ ![Codeship Status for qubitdigital/logger](https://codeship.com/projects/1504d8b0-d965-0133-7924-56bde683aa9e/status?branch=master)](https://codeship.com/projects/143490)\n\nA namespaced stylish logger for the browser and node.\n\n![](https://cloud.githubusercontent.com/assets/621323/18617528/83dc16fa-7dc9-11e6-825f-dfbb4d2fa891.png)\n\n\n### Example\n\n```js\nvar driftwood = require('driftwood')\n\nvar log = driftwood('a-module')\n\nlog.trace('It supports node and the browser!')\nlog.debug('You can', { also: 'send some arbitrary metadata!' })\n\nvar subLog = log('a-sub-module')\n\nsubLog.info('You can create loggers off loggers')\nsubLog.warn('So that your logs remain under the same top namespace')\nsubLog.error('Isn\\'t this cool?')\n```\n\nEnabling log output globally:\n\n```js\ndriftwood.enable() // defaults to { '*': 'info' }\ndriftwood.enable({\n  'foo': 'info',\n  'bar:*': 'debug'\n}, { persist: true }) // pass `persist: true` when in the browser to keep logging enabled across pages\n```\n\nEnabling log output for specific loggers or subloggers:\n\n```js\nvar log = driftwood('a-module')\nvar subLog = log('a-sub-module')\nlog.enable() // enables log and subLog\n\nvar log = driftwood('a-module')\nvar subLog = log('a-sub-module')\nsubLog.enable() // enables just subLog\n\nlog.disable() // disables log and sublog\n```\n\n\n### API\n\n### `driftwood.enable(config, options)`\n\nEnables all loggers globally using the optional log level config. The config is a map of name patterns to log level, defaulting to `{ '*': 'info' }`. See below for more pattern examples. You can also pass an options object to the enable function. Currently it only supports the `persist` option, which lets keep logging enabled across page views (defaults to false, only supports the browser).\n\n### `driftwood.disable()`\n\nDisables all loggers globally and clears the global log config.\n\n### `driftwood(name, [additionalLoggers, [interceptors]])`\n\nCreates a new named log instance, optionally supplying additional loggers (e.g. sentry or devtools). `additionalLoggers` should be an array of functions accepting 4 arguments:\n\n```js\nfunction (name, level, now, { message, error, metadata }) {\n  // do whatever\n}\n```\n\n`interceptors` is an array of functions used to change those arguments before they pass into the loggers:\n\n```js\nfunction (name, level, now, { message, error, metadata }) {\n  return [newName, newLevel, newDate, {\n    message: newMessage,\n    error: newError,\n    metadata: newMetadata\n  }]\n}\n```\n\nFor convenience, the return value can be one of:\n\n* `[name, level, now, { message, error, metadata }]`, to transform each of the four arguments,\n* `{ message, error, metadata }`, to transform only the main components of the message,\n* `message`, to transform only the main message, or\n* a falsey value, to transform nothing.\n\nThe interceptors are run sequentially from left to right, _before_ any (additional) loggers.\n\n### `log(name, [additionalLoggers, [interceptors]])`\n\nCreates a sub logger that inherits the namespace of its parent.\n\n```js\nvar log = driftwood('foo') // namespace will be foo\nvar subLog = log('bar') // namespace will be foo:bar\n```\n\nWhen using the sub logger, any `additionalLoggers` and/or `interceptors` provided will run _alongside_ the ones provided to the original logger. When using the original logger, the new functions are not run. All interceptors run _before_ all additional loggers. Within those groups, the original functions run _before_ the new functions. For example:\n\n```js\nfunction makeImportant(name, level, now, { message }) { return 'important ' + message }\nfunction capitalize(name, level, now, { message }) { return message.toUpperCase() }\nvar log = driftwood('foo', [], [makeImportant])\nvar subLog = log('bar', [], [capitalize])\nlog.info('message')         // logs: important message\nsubLog.info('proclamation') // logs: IMPORTANT PROCLAMATION\n```\n\n### `log.enable(config)`\n\nEnables a specific logger with a config object (see driftwood.enable). This will be applied to the logger and all of it's descendants.\n\n### `log.disable(config)`\n\nDisables a specific logger and all of it's descendants.\n\n### `log.{LEVEL}(message, [message], [metadata/Error])`\n\nLogs a message at a level, optionally with a metadata object or error instance. Available levels:\n\n- `trace`\n- `debug`\n- `info`\n- `warn`\n- `error`\n\nThe last argument of the log call can be an object or an instance of `Error`, which Driftwood will attempt to present in a more readable fashion. All preceding arguments will be concatenated together into a string.\n\n\n### Enabling logging\n\nBy default the logger will not output anything. You need to enable it first, as specified above. Below are some examples of log configs you can pass (you can use `*` as a wildcard:\n\n- `{ '*': null }` - will log everything at the default level (`info`)\n- `{ 'foo': 'trace' }` - will log anything from the logger with the name `foo` at the `trace` level\n- `{ 'foo': 'trace', 'bar*': 'warn' }` - will log `foo` at `trace` and `bar*` at `warn`\n- `{ 'foo*': 'error', '*': 'info' }` - will only log up to error from `foo*` and up to info from everything else\n\nWhen running in the browser, you can pass a `persist` flag to persist the log configuration into `localStorage`:\n\n```js\ndriftwood.enable({ '*': 'info' }, { persist: true })\n```\n\n### Disabling timestamps\n\nIf you prefer to not have timestamps on your logs, you can turn them off in a nodejs environment by setting the `DRIFTWOOD_NO_TIMESTAMP` environment variable to a truthy value.\n\n```sh\n  $ DRIFTWOOD_NO_TIMESTAMP=1 node ./myApp.js\n```\n\n### Best practices\n\nCreate a main `logger.js` file in your module/app:\n\n```js\n// logger.js\nvar driftwood = require('driftwood')\nmodule.exports = driftwood('my-app')\n```\n\nIn the main part of your app, use the main logger:\n\n```js\n// index.js\nvar log = require('./logger')\nlog.debug('We are in the entry of the app!')\n```\n\nIn each of your submodules, create a sub logger:\n\n```js\n// subModuleA.js\nvar log = require('./logger')('sub-module-a')\nlog.debug('We are in a submodule of the app!')\n```\n\n### Want to work on this for your day job?\n\nThis project was created by the Engineering team at [Qubit](http://www.qubit.com). As we use open source libraries, we make our projects public where possible.\n\nWe’re currently looking to grow our team, so if you’re a JavaScript engineer and keen on ES2016 React+Redux applications and Node micro services, why not get in touch? Work with like minded engineers in an environment that has fantastic perks, including an annual ski trip, yoga, a competitive foosball league, and copious amounts of yogurt.\n\nFind more details on our [Engineering site](https://eng.qubit.com). Don’t have an up to date CV? Just link us your Github profile! Better yet, send us a pull request that improves this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqubitproducts%2Fdriftwood","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqubitproducts%2Fdriftwood","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqubitproducts%2Fdriftwood/lists"}