{"id":17301911,"url":"https://github.com/tigercosmos/node-color-log","last_synced_at":"2025-04-06T10:11:35.947Z","repository":{"id":26849373,"uuid":"110136664","full_name":"tigercosmos/node-color-log","owner":"tigercosmos","description":"⌨️ The more powerful JavaScript logger for NodeJS and browsers ✏️","archived":false,"fork":false,"pushed_at":"2024-03-10T12:25:50.000Z","size":959,"stargazers_count":68,"open_issues_count":1,"forks_count":19,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-14T05:14:37.820Z","etag":null,"topics":["color","javascript","logger","nodejs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/node-color-log","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/tigercosmos.png","metadata":{"files":{"readme":"README.md","changelog":"change.log.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-09T16:05:10.000Z","updated_at":"2024-05-13T06:28:16.916Z","dependencies_parsed_at":"2024-05-13T06:28:15.293Z","dependency_job_id":"72b3c85f-237b-49a3-8101-a8199fc32968","html_url":"https://github.com/tigercosmos/node-color-log","commit_stats":{"total_commits":87,"total_committers":11,"mean_commits":7.909090909090909,"dds":0.4022988505747126,"last_synced_commit":"f2907c1fc67793470096f636c63b3ab49677f7e8"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigercosmos%2Fnode-color-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigercosmos%2Fnode-color-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigercosmos%2Fnode-color-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigercosmos%2Fnode-color-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tigercosmos","download_url":"https://codeload.github.com/tigercosmos/node-color-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247464222,"owners_count":20942970,"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":["color","javascript","logger","nodejs"],"created_at":"2024-10-15T11:45:55.797Z","updated_at":"2025-04-06T10:11:35.918Z","avatar_url":"https://github.com/tigercosmos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Banner](https://raw.githubusercontent.com/tigercosmos/node-color-log/master/assets/banner.png)\n\n[![Test](https://github.com/tigercosmos/node-color-log/actions/workflows/test.yml/badge.svg)](https://github.com/tigercosmos/node-color-log/actions/workflows/test.yml)\n[![npm version](https://badge.fury.io/js/node-color-log.svg)](https://badge.fury.io/js/node-color-log)\n[![npm downloads](https://badgen.now.sh/npm/dm/node-color-log)](https://www.npmjs.com/package/node-color-log)\n\n# Node Color Log\n\nA lightweight and more JavaScript logger for NodeJS and browsers.\n\n`node-color-log` is a logger package for NodeJS and browsers. It provides more functions than the origin `console.log`. You can log text with colorful fonts and colorful backgrounds. Also, it has 4 levels log, including `debug`, `info`, `warn` and `error`. Give you a much better experience while developing JavaScript projects.\n\nWinston and Pino are famous loggers for JavaScript, but they are too heavy and fancy. Sometimes we just want to have a simple logger, and don't want to spend time learning a fancy library. Then, `node-color-log` is your best choice.\n\n## Demo\n\n\u003cimg alt=\"Demo\" src=\"https://raw.githubusercontent.com/tigercosmos/node-color-log/master/assets/demo-log.png\" width=\"800\"\u003e\n\n\u003cimg alt=\"Demo\" src=\"https://raw.githubusercontent.com/tigercosmos/node-color-log/master/assets/demo-color.png\" width=\"800\"\u003e\n\n\u003cimg alt=\"Demo\" src=\"https://raw.githubusercontent.com/tigercosmos/node-color-log/master/assets/demo-level.png\" width=\"800\"\u003e\n\n## Usage\n\n### Install\n\nInstall package in your project:\n\n```bash\nnpm install node-color-log@latest --save\n```\n\n### Import\n\nPut the following code in your `js` in which you want to log.\n\n```javascript\nconst logger = require('node-color-log');\n```\n\nLogger level can be set like this. Logs belongs to this level and above that level will be printed.\n\n```javascript\nlogger.setLevel(\"error\"); // it can be any log level.\n```\n\n## API\n\n### `log()`\n\nlog with attributes, the order of setters can change.\n\n**NOTE:** `log()` need to put behind of attribute setter(at the end).\n\n`append()` can appends the contents in one line. (Note: old `joint` is now deprecated.)\n\n`color()` and `bgColor()` includes: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`.\n\n`reset()` can clear the previous attributes in the same line.\n\nUsage:\n\n```javascript\n// normal log\nlogger.log(message)\n// Attribute log\nlogger.color('red').bgColor('blue')\n      .bold().italic().dim().reverse().underscore().strikethrough()\n      .log(message);\n// use `append` to joint contents, and use `log` to print out at the end\nlogger.color('red').bold().append('message_style_1')\n      .bgColor('white').italic().append('message_style_2')\n      .strikethrough().log('message_style_3');\n\n// use `reset` to clean the attributes\nlogger.bgColor('red').append('background red color message')\n      .reset() // by calling this, background is reset\n      .log('default background color message');\n\n// log multiple arguments\nlogger.log(obj1, arr2, str3);\n```\n\n### `setLogStream`\n\nYou can redirect the logs to the stream.\n\nFor example, you can write the log into the file:\n\n```js\nfileStream = fs.createWriteStream('test.log'),\nlogger.setLogStream(fileStream)\n\nlogger.log(\"hi\");\nlogger.error(\"hello\", \"world\");\n\nfileStream.close()\n```\n\nYou can use `less -R test.log` to see the result.\n\n### `fontColorLog()`, `bgColorLog()`, `colorLog()`\n\n- `message` here must be a string.\n\n- Color includes: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`.\n\n- `setting` is optional. Keys in `setting` need to be boolean, and all are `false` by default.\n\nParameters:\n\n```javascript\nconst color = 'red';\nconst message = 'any string you will put into console.log';\nconst setting = {\n    bold: true,\n    dim: true,\n    underscore: true,\n    reverse: true,\n    italic: true,\n    strikethrough: true\n}\n```\n\nUsage:\n\n```javascript\n// only set font color\nlogger.fontColorLog('red', message, setting);\n// only set background color\nlogger.bgColorLog('yellow', message, setting);\n// set font and background color\nlogger.colorLog({\n    font: 'black',\n    bg: 'yellow'\n}, message, setting);\n```\n\n### `success()`, `debug()`, `info()`, `warn()`, `error()`\n\nWith prefix that has background color\n\nUsage:\n\n```javascript\n// Success level, with prefix \"[SUCCESS]\"\nlogger.success(message);\n// debug level, with prefix \"[DEBUG]\"\nlogger.debug(message);\n// Info level, with prefix \"[INFO]\"\nlogger.info(message);\n// Warn level, with prefix \"[WARN]\"\nlogger.warn(message);\n// Error level, with prefix \"[ERROR]\"\nlogger.error(message);\n\n\n// Level logs enable multiple arguments\nlogger.debug(obj1, arr2, str3);\n```\n\nThe output looks like:\n\n```log\n2018-08-14T18:23:09.836Z [SUCCESS] This is success mode\n2018-08-14T18:23:09.837Z [DEBUG] This is debug mode\n2018-08-14T18:23:09.838Z [INFO] This is info mode\n2018-08-14T18:23:09.838Z [WARN] This is warn mode\n2018-08-14T18:23:09.839Z [ERROR] This is error mode\n```\n\n### `setLevel()` \u0026 `LOGGER` environment variable\n\nIf you want to set mask for levels, simply add the line at the front. Levels below the setting level will all be hidden. There are four levels, which are `success`, `debug`, `info`, `warn`, `error`, or `disable` in lower-case.\n\n```js\nlogger.setLevel(\"info\"); // success \u003c debug \u003c info \u003c warn \u003c error \u003c disable\nlogger.debug(\"This `debug` will be hidden\");\nlogger.error(\"This `error` will be shown\");\n\nlogger.setLevel(\"disable\"); // hide every logs\n```\n\nOr, you can set the environment variable `LOGGER`, such as `LOGGER=info npm start`, where it's equal to `setLevel(\"info\")`.\n\n\n### `setLevelNoColor()`, `setLevelColor()`\n\nLevel logs print in colors as a default.\n\nYou can set `setLevelNoColor()` to turn off the setting, and use `setLevelColor()` to reverse it.\n\nNone color mode is helpful for text files or browser environments.\n\n```js\nlogger.setLevelNoColor();\n```\n\n### `setDate()`\n\nThe default time format is `toISOString`, but you can change it by using `setDate(callback)`\n\n```\nlogger.setDate(() =\u003e (new Date()).toLocaleTimeString())\nlogger.info(\"This is an info message\") // 5:17:59 pm [INFO] This is an info message\n```\n\n### `createNamedLogger()`\n\nYou can create a named logger by calling `createNamedLogger()`\n\n```\nlogger1 = logger.createNamedLogger(\"Test 1\");\nlogger2 = logger.createNamedLogger(\"Test 2\");\nlogger1.info('something happened'); // 2022-08-20T04:56:17.834Z [Test 1] [INFO] something happened\nlogger2.info('something happened'); // 2022-08-20T04:56:17.835Z [Test 2] [INFO] something happened \n```\n\n### Contribute\n\nAny issues and PRs are very welcome!\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigercosmos%2Fnode-color-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftigercosmos%2Fnode-color-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigercosmos%2Fnode-color-log/lists"}