{"id":15693685,"url":"https://github.com/doowb/log-events","last_synced_at":"2025-05-08T04:53:45.578Z","repository":{"id":65990629,"uuid":"52304271","full_name":"doowb/log-events","owner":"doowb","description":"Create custom, chainable logging methods that emit log events when called.","archived":false,"fork":false,"pushed_at":"2016-09-18T23:51:29.000Z","size":53,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T04:53:40.241Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/doowb.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}},"created_at":"2016-02-22T20:44:18.000Z","updated_at":"2023-06-22T01:27:16.000Z","dependencies_parsed_at":"2023-06-18T20:26:42.773Z","dependency_job_id":null,"html_url":"https://github.com/doowb/log-events","commit_stats":{"total_commits":44,"total_committers":1,"mean_commits":44.0,"dds":0.0,"last_synced_commit":"f74e7c9c58dc75ffd4670459ac76c1070eceb2e7"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Flog-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Flog-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Flog-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Flog-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/log-events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253002848,"owners_count":21838638,"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-10-03T18:47:09.308Z","updated_at":"2025-05-08T04:53:45.554Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# log-events [![NPM version](https://img.shields.io/npm/v/log-events.svg)](https://www.npmjs.com/package/log-events) [![Build Status](https://img.shields.io/travis/doowb/log-events.svg)](https://travis-ci.org/doowb/log-events)\n\n\u003e Create custom, chainable logging methods that emit log events when called.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install log-events --save\n```\n\n## Usage\n\n### [Logger](index.js#L25)\n\nCreate a new `Logger` constructor to allow\nupdating the prototype without affecting other contructors.\n\n### [._emit](index.js#L82)\n\nFactory for emitting log messages. This method is called internally for any emitter or mode method that is called as a function. To listen for events, listen for the emitter name or `'log'` when a mode is called as a method.\n\nWildcard `*` may also be listened for and will get 2 arguments `(name, stats)` where\n`name` is the emitter that was emitted and `stats` is the stats object for that event.\n\n**Params**\n\n* `name` **{String}**: the name of the emitter event to emit. Example: `info`\n* `message` **{String}**: Message intended to be emitted.\n* `returns` **{Object}** `Logger`: for chaining\n\n**Events**\n\n* `emits`: `*` Wildcard emitter that emits the emitter event name and stats object.\n* `emits`: `stats` Emitter that emits the stats object for the specified name.\n\n**Example**\n\n```js\n// emit `info` when `info` is an emitter method\nlogger.info('message');\n\n// emit `log` when `verbose` is a mode method\nlogger.verbose('message');\n\n// listen for all events\nlogger.on('*', function(name, stats) {\n  console.log(name);\n  //=\u003e info\n});\n\nlogger.info('message');\n```\n\n### [.emitter](index.js#L127)\n\nAdd an emitter method to emit an event with the given `name`.\n\n**Params**\n\n* `name` **{String}**: the name of the emitter event to emit.\n* `level` **{Number}**: Priority level of the emitter. Higher numbers are less severe. (Default: 100)\n* `fn` **{Function}**: Optional emitter function that can be used to modify an emitted message. Function may be an existing style function.\n* `returns` **{Object}** `this`: for chaining\n\n**Events**\n\n* `emits`: `emitter` Emits name and new emitter instance after adding the emitter method.\n\n**Example**\n\n```js\n// add a default `write` emitter\nlogger.emitter('write');\n\n// add some styles\nlogger.style('red', function(msg) {\n  return colors.red(msg);\n});\nlogger.style('cyan', function(msg) {\n  return colors.cyan(msg);\n});\n\n// add an `info` logger that colors the msg cyan\nlogger.emitter('info', logger.cyan);\n\n// use the loggers:\nlogger.red.write('this is a red message');\nlogger.info('this is a cyan message');\n```\n\n### [.mode](index.js#L175)\n\nAdd arbitrary modes to be used for creating namespaces for emitter methods.\n\n**Params**\n\n* `mode` **{String}**: Mode to add to the logger.\n* `options` **{Object}**: Options to describe the mode.\n* `options.type` **{String|Array}**: Type of mode being created. Defaults to `mode`. Valid values are `['mode', 'toggle']` `toggle` mode may be used to indicate a \"flipped\" state for another mode. e.g. `not.verbose` `toggle` modes may not be used directly for emitting log events.\n* `fn` **{Function}**: Optional style function that can be used to stylize an emitted message.\n* `returns` **{Object}** `this`: for chaining\n\n**Events**\n\n* `emits`: `mode` Emits the name and new mode instance after adding the mode method.\n\n**Example**\n\n```js\n// create a simple `verbose` mode\nlogger.mode('verbose');\n\n// create a `not` toggle mode\nlogger.mode('not', {type: 'toggle'});\n\n// create a `debug` mode that modifies the message\nlogger.mode('debug', function(msg) {\n  return '[DEBUG]: ' + msg;\n});\n\n// use the modes with styles and emitters from above:\nlogger.verbose.red.write('write a red message when verbose is true');\nlogger.not.verbose.info('write a cyan message when verbose is false');\nlogger.debug('write a message when debug is true');\n```\n\n### [Mode](lib/mode.js#L18)\n\nMode constructor for making a mode object when\na mode is created with `logger.mode()`\n\n**Params**\n\n* `options` **{Object}**: Options to configure the mode.\n* `options.name` **{String}**: Required name of the mode\n* `options.type` **{String|Type}**: Type of mode to create. Defaults to `mode`. Values may be `['mode', 'toggle']`.\n\n### [type](lib/mode.js#L43)\n\nType of `mode`. Valid types are ['mode', 'toggle']\n\n**Example**\n\n```js\nconsole.log(verbose.type);\n//=\u003e \"mode\"\nconsole.log(not.type);\n//=\u003e \"toggle\"\n```\n\n### [name](lib/mode.js#L69)\n\nReadable name of `mode`.\n\n**Example**\n\n```js\nconsole.log(verbose.name);\n//=\u003e \"verbose\"\nconsole.log(not.name);\n//=\u003e \"not\"\n```\n\n### [](lib/mode.js#L97)`fn`\n\nOptional modifier function that accepts a value and returns a modified value. When not present, an identity function is used to return the original value.\n\n**Example**\n\n```js\nvar msg = \"some error message\";\n\n// wrap message in ansi codes for \"red\"\nmsg = red.fn(msg);\nconsole.log(msg);\n\n//=\u003e \"\\u001b[31msome error message\\u001b[39m\";\n```\n\n### [Stats](lib/stats.js#L33)\n\nStats contructor that contains information about a chained event being built up.\n\n**Params**\n\n* `parent` **{Object}**: Optional stats instance to inherit `modes` and `styles` from.\n\n**Example**\n\n```js\n{\n  // \"not\" =\u003e toggle, \"verbose\" =\u003e mode\n  modes: ['not', 'verbose'],\n\n  // \"red\" =\u003e modifier\n  styles: ['red'],\n\n  // specified when emitter is created\n  level: 1,\n\n  // name of emitter that will trigger an event\n  // in this case \"red\" will not trigger an event\n  name: 'subhead',\n\n  // arguments passed into emitter function \"subhead\"\n  args: ['foo', 'bar', 'baz']\n}\n```\n\n### [.addMode](lib/stats.js#L80)\n\nAdd a mode to the `modes` array for this stats object.\n\n**Params**\n\n* `mode` **{Object}**: Instance of a Mode to add to the stats object.\n* `returns` **{Object}** `this`: for chaining.\n\n**Example**\n\n```js\nvar verbose = new Mode({name: 'verbose'});\nstats.addMode(verbose);\n```\n\n### [.getModes](lib/stats.js#L101)\n\nGet the array of modes from the stats object. Optionally, pass a property in and return an array with only the property.\n\n**Params**\n\n* `prop` **{String}**: Optional property to pick from the mode objects to return.\n* `returns` **{Array}**: Array of modes or mode properties.\n\n**Example**\n\n```js\nvar modes = stats.getModes();\n//=\u003e [{name: 'verbose'}]\nvar modeNames = stats.getModes('name');\n//=\u003e ['verbose']\n```\n\n### [.addStyle](lib/stats.js#L120)\n\nAdd a style to the `styles` array for this stats object.\n\n**Params**\n\n* `style` **{String}**: Name of style to add.\n* `returns` **{Object}** `this`: for chaining.\n\n**Example**\n\n```js\nstats.addStyle('red');\n```\n\n### [.addEmitter](lib/stats.js#L137)\n\nSets the emitter for this stats object to indicate this is a complete stats object ready to be emitted.\n\n**Params**\n\n* `emitter` **{Object}**: Instance of a Emitter to add to the stats object.\n* `returns` **{Object}** `this`: for chaining.\n\n**Example**\n\n```js\nvar info = new Emitter({name: 'info'});\nstats.addEmitter(info);\n```\n\n## Related projects\n\n* [falsey](https://www.npmjs.com/package/falsey): Returns true if `value` is falsey. Works for strings, arrays and `arguments` objects with a… [more](https://www.npmjs.com/package/falsey) | [homepage](https://github.com/jonschlinkert/falsey)\n* [is-enabled](https://www.npmjs.com/package/is-enabled): Using key paths that may contain \"falsey\" patterns, check if a property on an object… [more](https://www.npmjs.com/package/is-enabled) | [homepage](https://github.com/doowb/is-enabled)\n* [verbalize](https://www.npmjs.com/package/verbalize): A pluggable logging utility with built-in colors, styles, and modes. | [homepage](https://github.com/jonschlinkert/verbalize)\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/log-events/issues/new).\n\n## Building docs\n\nGenerate readme and API documentation with [verb][]:\n\n```sh\n$ npm install verb \u0026\u0026 npm run docs\n```\n\nOr, if [verb][] is installed globally:\n\n```sh\n$ verb\n```\n\n## Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d \u0026\u0026 npm test\n```\n\n## Author\n\n**Brian Woodward**\n\n* [github/doowb](https://github.com/doowb)\n* [twitter/doowb](http://twitter.com/doowb)\n\n## License\n\nCopyright © 2016 [Brian Woodward](https://github.com/doowb)\nReleased under the [MIT license](https://github.com/doowb/log-events/blob/master/LICENSE).\n\n***\n\n_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on March 07, 2016._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Flog-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Flog-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Flog-events/lists"}