{"id":16805931,"url":"https://github.com/haltcase/logger-neue","last_synced_at":"2026-05-16T23:05:01.140Z","repository":{"id":57290614,"uuid":"74873552","full_name":"haltcase/logger-neue","owner":"haltcase","description":"Doing for Node logging what Neue did for Helvetica.","archived":false,"fork":false,"pushed_at":"2020-07-18T02:45:02.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-25T18:08:11.095Z","etag":null,"topics":["console","esm","hacktoberfest","log","logger","logging","modules","neue","node","typescript"],"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/haltcase.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","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-11-27T07:24:35.000Z","updated_at":"2021-05-07T15:24:14.000Z","dependencies_parsed_at":"2022-08-28T05:52:37.121Z","dependency_job_id":null,"html_url":"https://github.com/haltcase/logger-neue","commit_stats":null,"previous_names":["citycide/logger-neue"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Flogger-neue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Flogger-neue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Flogger-neue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haltcase%2Flogger-neue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haltcase","download_url":"https://codeload.github.com/haltcase/logger-neue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244011081,"owners_count":20383357,"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":["console","esm","hacktoberfest","log","logger","logging","modules","neue","node","typescript"],"created_at":"2024-10-13T09:49:39.268Z","updated_at":"2026-05-16T23:04:56.102Z","avatar_url":"https://github.com/haltcase.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# logger-neue \u0026middot; [![Version](https://flat.badgen.net/npm/v/logger-neue)](https://www.npmjs.com/package/logger-neue) [![License](https://flat.badgen.net/npm/license/logger-neue)](https://www.npmjs.com/package/logger-neue) [![Travis CI](https://flat.badgen.net/travis/citycide/logger-neue)](https://travis-ci.org/citycide/logger-neue) [![TypeScript](https://flat.badgen.net/badge/written%20in/TypeScript/294E80)](http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html)\n\n_logger-neue_ is an attempt to refine the concept of logging in Node. It aims\nto be easier to configure than similar projects like [`winston`][winston]\nfor simple features like custom log levels and file output.\n\nIt also has basic support for Node-ish environments like Electron's renderer,\nwhere it will write to the developer tools console.\n\nSince v2, _logger-neue_ is written in strict TypeScript and includes type definitions. :tada:\n\n[installation](#installation) \u0026middot; [usage](#usage) \u0026middot; [api](#api) \u0026middot; [defaults](#defaults) \u0026middot; [templates](#templates) \u0026middot; [events](#events) \u0026middot; [contributing](#contributing) \u0026middot; [license](#license)\n\n## installation\n\n1. install\n\n   Using [Yarn][yarn]:\n\n   ```console\n   yarn add logger-neue\n   ```\n\n   Or using npm:\n\n   ```console\n   npm install logger-neue\n   ```\n\n2. import\n\n   In TypeScript / ES2015+:\n\n   ```ts\n   import { createLogger } from \"logger-neue\"\n   ```\n\n   In ES5 / commonjs:\n\n   ```js\n   const { createLogger } = require(\"logger-neue\")\n   ```\n\n## usage\n\nWhile _logger-neue_ is highly configurable, minimum configuration for a\nprettier alternative to the standard `console.log` is as simple as:\n\n```js\nconst log = createLogger()\n```\n\nOr even prettier, with full color:\n\n```js\nconst log = createLogger({\n  console: { fullColor: true }\n})\n```\n\nBelow is an example of a more thorough configuration. Note that there's no\nneed to pass a write stream for the file or deal with a complicated transports\nconfiguration. You just have to define `options.file` and provide a `path`\n\u0026mdash; _logger-neue_ does the rest.\n\n```js\nimport { createLogger } from \"logger-neue\"\n\nimport { dirname } from \"path\"\n\nconst log = createLogger({\n  file: {\n    // if relative, resolved using `process.cwd()`\n    path: \"./test.log\",\n    // to specify the base directory, also pass the `dir` property\n    dir: dirname(import.meta.url),\n    // level defaults to \"error\"\n    level: \"error\"\n  },\n  console: {\n    // pass either a string or number\n    // resolved against the log level map below\n    level: process.env.NODE_ENV === \"development\" ? \"trace\" : \"error\",\n    // if set to true, uses the `colors` option of `util.inspect`\n    // for all logged arguments, regardless of type\n    fullColor: true\n  },\n  levels: {\n    // the level map to be used for both file \u0026 console\n    // this example uses array syntax\n    error:  [0, [\"red\", \"bold\", \"underline\"]],\n    // array[0] = the log level\n    // array[1] = an array ( or single string ) of colorette modifiers\n    warn:   [1, \"yellow\"],\n    info:   [2, \"magenta\"],\n    debug:  [3, \"cyan\"],\n    // undefined or invalid `style` defaults to \"white\"\n    trace:  [4],\n    absurd: [5, \"gray\"],\n\n    // levels can also be defined with object syntax:\n    ridiculous: {\n      level: 6,\n      style: [\"blue\", \"bgYellow\", \"underline\", \"italic\"]\n    }\n  }\n})\n```\n\n## api\n\n### createLogger\n\n```js\ncreateLogger(options)\n```\n\nThere are actually two ways to create a new instance \u0026mdash; you can use the\n`createLogger` factory function or the `LoggerNeue` class directly. This means\nthe following are (roughly) equivalent:\n\n```js\nimport { createLogger, LoggerNeue } from \"logger-neue\"\nconst logger1 = new LoggerNeue()\nconst logger2 = createLogger()\n```\n\nThe difference is that `LoggerNeue` is the raw class, and `createLogger` is a\nwrapper function that [provides helpful type information][impl] based on your provided\nlevel definitions.\n\n\u003e **Arguments**\n\n  - _optional_ `{object} options`:\n\n  | property  | type       | default     | description                       |\n  | --------- | :--------: | :---------: | --------------------------------- |\n  | `file`    | `object` or `false` | `false`        | Configuration for file output.    |\n  | `console` | `object`   | _see below_ | Configuration for console output. |\n\n  `options.file`:\n\n  | property   | type            | default         | description                         |\n  | ---------- | :-------------: | :-------------: | ----------------------------------- |\n  | `dir`      | `string`        | `process.cwd()` | Base directory with which to resolve `path`.  |\n  | `level`    | `string` or `number` | `0` or `error`  | Number or name of the output level. |\n  | `path`     | `string`        | -               | Path to the log file, resolved with `dir` if relative. |\n  | `template` | `string`        | [_see here_](#default-templates) | [`strat`][strat] compatible template with which to format the output. See [templates](#templates) for more. |\n\n  `options.console`:\n\n  | property    | type            | default         | description                         |\n  | ----------- | :-------------: | :-------------: | ----------------------------------- |\n  | `fullColor` | `boolean`       | `false` | Whether to apply color to all types of values. |\n  | `level`     | `string` or `number` | `2` or `info`  | Number or name of the output level. |\n  | `template`  | `string`        | [_see here_](#default-templates) | [`strat`][strat] compatible template with which to format the output. See [templates](#templates) for more. |\n\n  `options.levels`:\n\n  If provided as an object, it should have these properties:\n\n  |  property  | type       | default     | description                       |\n  | ---------- | :--------: | :---------: | --------------------------------- |\n  | `level`    | `number`   | `0`         | Determines when this log method fires. |\n  | `style`   | `string` or `string[]` | - | [`colorette`][styles] styles for terminal output, either a single string or array of styles. |\n  | `isError`  | `boolean`  | `false`     | If `true`, target `stderr` instead of `stdout`. |\n\n  If provided as an array, it should take the form of `[level, style, isError]`\n\n### addLevel\n\n```js\naddLevel(name, properties)\n```\n\n\u003e **Arguments**\n\n  - `{string} name`\n  - `{Object} properties`:\n\n  If provided as an object, it should have these properties:\n\n  |  property  | type       | default     | description                       |\n  | ---------- | :--------: | :---------: | --------------------------------- |\n  | `level`    | `number`   | `0`         | Determines when this log method fires. |\n  | `style`   | `string` or `string[]` | - | [`colorette`][styles] styles for terminal output, either a single string or array of styles. |\n  | `isError`  | `boolean`  | `false`     | If `true`, target `stderr` instead of `stdout`. |\n\n  If provided as an array, it should take the form of `[level, style, isError]`\n\n### log\n\n```js\nlog(level, ...args)\n```\n\nAlternative method of calling a log level. The following are equivalent:\n\n```js\nlog.error(\"fail\")\nlog(\"error\", \"fail\")\n\n// can also call by level number\nlog(0, \"fail\")\n```\n\n\u003e **Arguments**\n\n  - `{string|number} level`: name or number of the log level to trigger\n  - `{...any} args`: arguments passed to the log level function\n\n### getLevelByNumber\n\n```js\ngetLevelByNumber(number)\n```\n\n\u003e **Arguments**\n\n  - `{number} number`: number to search levels for\n\n\u003e **Returns**\n\n`{string}`: name of the associated level\n\n### getNumberOfLevel\n\n```js\ngetNumberOfLevel(name)\n```\n\n\u003e **Arguments**\n\n  - `{string} name`: name of the level to search for\n\n\u003e **Returns**\n\n`{number}`: logging level of `name`\n\n### getLevelNames\n\n```js\ngetLevelNames()\n```\n\n\u003e **Returns**\n\n`{string[]}`: array of all log level names\n\n### getConsoleLevel\n\n```js\ngetConsoleLevel()\n```\n\n\u003e **Returns**\n\n`{number}`: the current logging level for console output\n\n### setConsoleLevel\n\n```js\nsetConsoleLevel(level)\n```\n\nSet the logging level for console output. Any levels below this are not output.\n\n\u003e **Arguments**\n\n`{string|number}`: either the name of the level or its logging level number\n\n### getFileLevel\n\n```js\ngetFileLevel()\n```\n\n\u003e **Returns**\n\n`{number}`: the current logging level for file output\n\n### setFileLevel\n\n```js\nsetFileLevel(level)\n```\n\nSet the logging level for file output. Any levels below this are\nnot output.\n\n\u003e **Arguments**\n\n`{string|number}`: either the name of the level or its logging level number\n\n## defaults\n\n_logger-neue_ attempts to make setup as painless as possible,\nwhich means it uses sane defaults to allow for minimal or zero configuration.\n\nWithout providing a config object, _logger-neue_ uses the following\ndefaults:\n\n```js\noptions = {\n  // no file output\n  file: false,\n  console: {\n    // will output \"info\", \"warn\", and \"error\"\n    level: \"info\",\n    // does not apply color to primitives\n    fullColor: false,\n    template: \"{level}{padding}  {input}\"\n  },\n  levels: {\n    //       [level, style, isError]\n    error:   [0, [\"red\", \"bgBlack\"], true],\n    warn:    [1, [\"black\", \"bgYellow\"], false],\n    info:    [2, [\"green\"], false],\n    verbose: [3, [\"blue\", \"bgBlack\"], false],\n    debug:   [4, [\"cyan\"], false],\n    silly:   [5, [\"inverse\"], false]\n  }\n}\n```\n\nIf `options.file.path` is provided, these defaults are used for the rest of\nthe properties in `options.file`:\n\n```js\noptions.file = {\n  // used as base directory if `path` is relative\n  dir: process.cwd(),\n  // only outputs \"error\"\n  level: 0,\n  template:\n    `{{\"level\":{level!json},` +\n    `\"input\":{args!json},` +\n    `\"timestamp\":{timestamp!json}}}`\n}\n```\n\nThis means a console-only config can be as simple as:\n\n```js\nconst logger = createLogger()\n```\n\n... and adding additional output to a file can be as simple as:\n\n```js\nconst logger = createLogger({\n  file: { path: \"./log.txt\" }\n})\n```\n\n## templates\n\nThe [`strat`][strat] module is used to format all output strings. The templates\nare customizable by passing them to the `console` or `file` options objects at\nconstruction time.\n\nYou can also use the `format()` method of any log level to pass a template to\nbe interpolated.\n\n### variables\n\nThe variables replaced from a template are:\n\n| name    | description |\n| ------- | ----------- |\n| `args`  | Array of the raw arguments passed to the log function. |\n| `padding` | String of spaces for use in aligning log levels of varying lengths. |\n| `input` | Array of the arguments after they've been processed \u0026 stylized. |\n| `level` | Name of the log level, stylized by default with `colorette` for terminals. |\n| `timestamp` | Defaults to an ISO string timestamp of log time. |\n\n### presets\n\nSeveral template presets are exported for your usage:\n\n```js\nimport { createLogger, templatePresets } from \"logger-neue\"\n\nconst log = createLogger({\n  console: {\n    fullColor: true,\n    template: templatePresets.bracketedLevel\n  }\n})\n\nlog.info(\"hello there!\")\n// -\u003e [info]        hello there!\n\nlog.ridiculous(\"hello again!\")\n// -\u003e [ridiculous]  hello again!\n```\n\n\u003ca name=\"default-templates\"\u003e\u003c/a\u003e\n\n| name             | template                                  |\n| ---------------- | ----------------------------------------- |\n| `alignLeft`¹     | `{level}{padding}  {input}`               |\n| `alignRight`     | `{padding}{level}  {input}`               |\n| `separatedColon` | `{level}: {input}`                        |\n| `bracketedLevel` | `[{level}]{padding}  {input}`             |\n| `jsonTimestamp`² | `{{\"level\":{level!json},\"input\":{args!json},\"timestamp\":{timestamp!json}}}` |\n\n_¹ default console template_\u003cbr/\u003e\n_² default file template_\n\n### transformers\n\nTemplates also support transformers \u0026mdash; functions that modify the above\nvariables just by appending them to the variable name after a `!`, like\nthis substring taken from the default `file` template:\n\n```js\n\"{level!json}\"\n```\n\nThe `json` transformer stringifies its argument, `level` in this case.\n\nAll the transformers available are:\n\n| name    | description                               |\n| ------- | ----------------------------------------- |\n| `upper` | Upper cases the argument                  |\n| `lower` | Lower cases the argument                  |\n| `paren` | Wraps the argument in parentheses         |\n| `brace` | Wraps the argument in braces (`[]`)       |\n| `curly` | Wraps the argument in curly braces (`{}`) |\n| `json`  | JSON stringifies the argument             |\n\nSee the [`strat`][strat] documentation for more details about how these\ntransformers work.\n\n## events\n\nEach instance of _logger-neue_ is also an event emitter, so you can use all\nmethods of Node's [`EventEmitter`][node_events] on it:\n\n```js\nconst log = createLogger()\nlog.on(\"log\", event =\u003e {\n  const { name, level, args } = event\n})\n\nlog.on(\"log:info\", event =\u003e {\n  // only `log.info()` will trigger this\n  const { name, level, args } = event\n})\n\nlog.once(/* ... */)\nlog.removeAllListeners()\n// etc\n```\n\nThere are also events emitted prior to the log being output \u0026mdash; just\nprepend `pre:` to the events in the above example. These events provide\nthe same fields but with the addition of a `prevent()` function. Calling\nthis function prevents the log from being output.\n\n```js\nlog.on(\"pre:log\", event =\u003e {\n  const { name, level, args, prevent } = event\n})\n\nlog.on(\"pre:log:trace\", event =\u003e {\n  // prevent all output when `log.trace()` is called\n  event.prevent()\n})\n```\n\n## contributing\n\nThis project is open to contributions of all kinds! Please check and search\nthe [issues][issues] if you encounter a problem before opening a new one.\n[Pull requests][prinfo] for improvements are also welcome.\n\n1. Fork the project, and preferably create a branch named something like `feat-make-better`\n2. Modify the source files in the `src` directory as needed\n3. Run `npm test` to make sure all tests continue to pass, and it never hurts to have more tests\n4. Commit, push, and open a pull request.\n\n## see also\n\n- [strat][strat] \u0026ndash; string formatting library at home in ES2015+ JavaScript\n- [colorette][colorette] \u0026ndash; terminal string styling done right\n\n## license\n\nMIT © [Bo Lingen / citycide](https://github.com/citycide)\n\n[winston]: https://github.com/winstonjs/winston\n[yarn]: https://yarnpkg.com\n[colorette]: https://github.com/jorgebucaran/colorette\n[strat]: https://github.com/citycide/strat\n[node_events]: https://nodejs.org/api/events.html#events_class_eventemitter\n[styles]: https://github.com/jorgebucaran/colorette#styles\n[impl]: https://github.com/citycide/logger-neue/blob/fd4b2ba33303aedb46745b520f3873ae5be4a809/src/index.ts#L143-L145\n\n[issues]: https://github.com/citycide/logger-neue/issues\n[prinfo]: https://help.github.com/articles/creating-a-pull-request/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaltcase%2Flogger-neue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaltcase%2Flogger-neue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaltcase%2Flogger-neue/lists"}