{"id":17855624,"url":"https://github.com/nebrius/transport-logger","last_synced_at":"2025-04-02T18:15:07.758Z","repository":{"id":21559800,"uuid":"24879559","full_name":"nebrius/transport-logger","owner":"nebrius","description":"Transport based synchronous logging for Node.js","archived":false,"fork":false,"pushed_at":"2016-02-12T06:33:49.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-13T08:24:20.344Z","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/nebrius.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":"2014-10-07T06:39:26.000Z","updated_at":"2016-02-12T06:17:59.000Z","dependencies_parsed_at":"2022-07-16T13:30:40.852Z","dependency_job_id":null,"html_url":"https://github.com/nebrius/transport-logger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Ftransport-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Ftransport-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Ftransport-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Ftransport-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nebrius","download_url":"https://codeload.github.com/nebrius/transport-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246866100,"owners_count":20846496,"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-28T02:23:50.476Z","updated_at":"2025-04-02T18:15:07.737Z","avatar_url":"https://github.com/nebrius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Transport Logger\n================\n\nA multi-transport logger inspired by [winston](https://github.com/flatiron/winston) with the goal of being simple and small while still retaining some of the flexibility found in larger multi-transport loggers like winston.\n\n## Table of Contents\n* [Basic usage](#basic-usage)\n\t* [Default logging](#default-logging)\n\t* [Customizing the output](#customizing-the-output)\n\t* [Logging to a file](#logging-to-a-file)\n* [Using multiple transports](#using-multiple-transports)\n* [Custom log levels](#custom-log-levels)\n* [Named transports](#named-transports)\n* [Formatter functions](#formatter-functions)\n* [Complete API](#complete-api)\n* [License](#license)\n\n## Basic usage\n\nInstall via npm:\n\n```\nnpm install transport-logger\n```\n\n### Default logging\n\nInstantiating a logger without any arguments creates a console logger with five levels ('error', 'warn', 'info', 'debug', and 'trace') and a minimum logging level of 'info'.\n\n```JavaScript\nvar Logger = require('transport-logger');\nvar logger = new Logger();\n\nlogger.error('error');\nlogger.warn('warn');\nlogger.info('info');\nlogger.debug('debug');\nlogger.trace('trace');\n```\n\nwill print\n\n```JavaScript\nerror\nwarn\ninfo\n```\n\n### Customizing the output\n\nThe output can be customized as follows:\n\n```JavaScript\nvar Logger = require('transport-logger');\nvar logger = new Logger({\n  minLevel: 'trace',\n  timestamp: true,\n  prependLevel: true,\n  colorize: true\n});\n\nlogger.error('error');\nlogger.warn('warn');\nlogger.info('info');\nlogger.debug('debug');\nlogger.trace('trace');\n```\n\nwhich will print\n\n\u003cpre\u003e\n\u003cfont color=\"#800\"\u003e[ERROR] Sun May 05 2013 16:36:19 GMT-0700 (PDT): error\u003c/font\u003e\n\u003cfont color=\"#880\"\u003e[WARN] Sun May 05 2013 16:36:19 GMT-0700 (PDT): warn\u003c/font\u003e\n[INFO] Sun May 05 2013 16:36:19 GMT-0700 (PDT): info\n[DEBUG] Sun May 05 2013 16:36:19 GMT-0700 (PDT): debug\n[TRACE] Sun May 05 2013 16:36:19 GMT-0700 (PDT): trace\n\u003c/pre\u003e\n\nFurther customization of output can be accomplished using a formatter callback function. Custom log levels can also be specified. For more information, read the [Complete API](#complete-api) section.\n\n### Logging to a file\n\nTo log to a file, specify a path in the options object:\n\n```JavaScript\nvar Logger = require('transport-logger');\nvar logger = new Logger({\n  destination: 'path/to/logfile'\n});\n\nlogger.error('error');\nlogger.warn('warn');\nlogger.info('info');\nlogger.debug('debug');\nlogger.trace('trace');\n```\n\nWhen logging to a file, it may be useful to cap files at a certain size. Setting the maxLines option will cause the current log file to be moved to a new filed called [destination].# once maxLines number of lines is reached. The number at the end the filename is incremented each time a new file is archived, such that [destination].1 is older than [destination].2\n\n```JavaScript\nvar Logger = require('transport-logger');\nvar logger = new Logger({\n  destination: 'path/to/logfile',\n  maxLines: 5\n});\n\nlogger.error('error');\nlogger.warn('warn');\nlogger.info('info');\nlogger.debug('debug');\nlogger.trace('trace'); // Will cause a new log file to be created\nlogger.info('new'); // Will be the first line logged to the new file\n```\n\n\n## Using multiple transports\n\nTo log to multiple transports, specify an array of configuration options\n\n```JavaScript\nvar Logger = require('transport-logger');\nvar logger = new Logger([{\n  destination: 'path/to/logfile',\n  minLevel: 'trace'\n}, {\n  minLevel: 'debug'\n}]);\n\nlogger.error('error');\nlogger.warn('warn');\nlogger.info('info');\nlogger.debug('debug');\nlogger.trace('trace');\n```\n\nTo use the default console logger as one of the transports, just specify an empty object\n\n## Custom log levels\n\nTo use custom log levels, specify an object mapping log level names to colors as the second argument to the Logger constructor:\n\n```JavaScript\nvar Logger = require('transport-logger');\nvar logger = new Logger({\n  minLevel: 'b',\n  colorize: true\n}, {\n  levels: [{\n    id: 'a',\n    color: 'red'\n  }, {\n    id: 'b',\n    color: 'green'\n  }, {\n    id: 'c',\n    color: 'blue'\n  }, {\n    id: 'd',\n    color: 'cyan'\n  }, {\n    id: 'e',\n    color: 'magenta'\n  }]\n});\n\nlogger.a('a');\nlogger.b('b');\nlogger.c('c');\nlogger.d('d');\nlogger.e('e');\n```\n\nAvailable colors are 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', and 'normal' (default terminal color). If not using colors, these can be any value.\n\nNote: if one of the transports is a console transport and the log level is not a native console method, the closest log level that is on console will be found. For example, if [syslog](http://en.wikipedia.org/wiki/Syslog#Severity_levels) levels are defined, then emergency, alert, and critical are specified, they will be logged via ```console.error()```.\n\n## Named transports\n\nEach transport can have a name assigned to it, so that they can be referenced later. With named transports, you can specify a different message for each transport in a log. This can be used, for example, to log a message that is localized for the user to the console, but log a message that is localized for the developer to a file.\n\n```JavaScript\nvar Logger = require('transport-logger');\nvar logger = new Logger([{\n  name: 'file',\n  destination: 'path/to/logfile'\n},{\n  name: 'console'\n}]);\nlogger.info({\n  console: 'Dies ist eine Nachricht',\n  file: 'This is a message'\n})\n```\n\n## Formatter functions\n\nIf the built-in options are not sufficient for your logging needs, you can define a formatter function to perform any arbitrary formatting:\n\n```JavaScript\nvar Logger = require('transport-logger');\nvar logger = new Logger({\n  formatter: function (messages, level, settings) {\n    return level.id + '?' + messages.join('+');\n  }\n});\n\nlogger.error('error', 'foo');\nlogger.warn('warn', 'foo');\nlogger.info('info', 'foo');\nlogger.debug('debug', 'foo');\nlogger.trace('trace', 'foo');\n```\n\nwill print\n\n```\nerror?error+foo\nwarn?warn+foo\ninfo?info+foo\n```\n\n## Complete API\n\n### Constructor\n\n```JavaScript\nnew Logger(transports, settings);\n```\n\n#### Parameters\n\n\u003ctable\u003e\n\t\u003ctr\u003e\n\t\t\u003cth\u003eName\u003c/th\u003e\n\t\t\u003cth\u003eType\u003c/th\u003e\n\t\t\u003cth\u003eDescription\u003c/th\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd\u003etransports \u0026lt;optional\u0026gt;\u003c/td\u003e\n\t\t\u003ctd\u003eObject | Array[Object]\u003c/td\u003e\n\t\t\u003ctd\u003eThe settings for the transport or transports\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd /\u003e\n\t\t\u003ctd colspan=\"2\"\u003e\n\t\t\t\u003ctable\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003cth\u003eName\u003c/th\u003e\n\t\t\t\t\t\u003cth\u003eType\u003c/th\u003e\n\t\t\t\t\t\u003cth\u003eDescription\u003c/th\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003ctd\u003etimestamp \u0026lt;optional\u0026gt;\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eBoolean\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eTimestamps each log message with a UTC date (default false)\u003c/td\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003ctd\u003eprependLevel \u0026lt;optional\u0026gt;\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eBoolean\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003ePrepends each log message with the log level (default false)\u003c/td\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003ctd\u003eminLevel \u0026lt;optional\u0026gt;\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eString\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eThe minimum logging level (default 'info'). If something falsey is passed in, then nothing is logged. This can be used to implement a --silent flag in the application\u003c/td\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003ctd\u003eformatter \u0026lt;optional\u0026gt;\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eFunction\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eA function to format messages with. An array of all messages to log is passed in as the only argument. The formatter function shall return a string that is logged\u003c/td\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003ctd\u003edestination \u0026lt;optional\u0026gt;\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eString | stream.Writable\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eThe path to the log file, or an existing stream. If a file path is specified, it does not have to exist already. If the file exists, new log messages are appended to the existing contents. Takes precedence over the stream property.\u003c/td\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003ctd\u003ename \u0026lt;optional\u0026gt;\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eString\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eThe name of the transport\u003c/td\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\u003c/table\u003e\n\t\t\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd\u003esettings \u0026lt;optional\u0026gt;\u003c/td\u003e\n\t\t\u003ctd\u003eObject\u003c/td\u003e\n\t\t\u003ctd\u003eThe global settings that apply to all transports\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd /\u003e\n\t\t\u003ctd colspan=\"2\"\u003e\n\t\t\t\u003ctable\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003cth\u003eName\u003c/th\u003e\n\t\t\t\t\t\u003cth\u003eType\u003c/th\u003e\n\t\t\t\t\t\u003cth\u003eDescription\u003c/th\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003ctd\u003elevels\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eObject\u003c/td\u003e\n\t\t\t\t\t\u003ctd\u003eThe custom levels for the logger\u003c/td\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\u003ctd /\u003e\n\t\t\t\t\t\u003ctd colspan=\"2\"\u003e\n\t\t\t\t\t\t\u003ctable\u003e\n\t\t\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\t\t\u003cth\u003eName\u003c/th\u003e\n\t\t\t\t\t\t\t\u003cth\u003eType\u003c/th\u003e\n\t\t\t\t\t\t\t\u003cth\u003eDescription\u003c/th\u003e\n\t\t\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\t\t\u003ctr\u003e\n\t\t\t\t\t\t\t\u003ctd\u003e\u0026lt;level name\u0026gt;\u003c/td\u003e\n\t\t\t\t\t\t\t\u003ctd\u003eString\u003c/td\u003e\n\t\t\t\t\t\t\t\u003ctd\u003eEach level name is specified as a key, and it's log color is the value\u003c/td\u003e\n\t\t\t\t\t\t\u003c/tr\u003e\n\t\t\t\t\t\u003c/td\u003e\n\t\t\t\t\u003c/tr\u003e\n\t\t\t\u003c/table\u003e\n\t\t\u003c/td\u003e\n\t\u003c/table\u003e\n\u003c/table\u003e\n\n#### Returns\n\nAn instance of the logger. Each logger instance has a method that corresponds with each log level. Each method takes an arbitrary number of arguments, converts them to strings, and contatenates them with a space in between them.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Bryan Hughes \u003cbryan@theoreticalideations.com\u003e (http://theoreticalideations.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnebrius%2Ftransport-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnebrius%2Ftransport-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnebrius%2Ftransport-logger/lists"}