{"id":16931633,"url":"https://github.com/romelperez/prhone-log","last_synced_at":"2026-05-21T07:04:35.997Z","repository":{"id":57330262,"uuid":"61140067","full_name":"romelperez/prhone-log","owner":"romelperez","description":"Simple JavaScript logger","archived":false,"fork":false,"pushed_at":"2017-05-24T01:25:18.000Z","size":49,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T09:47:58.451Z","etag":null,"topics":["javascript-logger","logger","logging"],"latest_commit_sha":null,"homepage":"","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/romelperez.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-06-14T16:51:59.000Z","updated_at":"2023-03-08T03:12:17.000Z","dependencies_parsed_at":"2022-09-21T02:02:45.456Z","dependency_job_id":null,"html_url":"https://github.com/romelperez/prhone-log","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romelperez%2Fprhone-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romelperez%2Fprhone-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romelperez%2Fprhone-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romelperez%2Fprhone-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romelperez","download_url":"https://codeload.github.com/romelperez/prhone-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244730672,"owners_count":20500494,"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":["javascript-logger","logger","logging"],"created_at":"2024-10-13T20:44:24.836Z","updated_at":"2026-05-21T07:04:35.905Z","avatar_url":"https://github.com/romelperez.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PRHONE Log\n\n[![npm version](https://badge.fury.io/js/prhone-log.svg)](https://badge.fury.io/js/prhone-log)\n[![Build Status](https://travis-ci.org/romelperez/prhone-log.svg?branch=master)](https://travis-ci.org/romelperez/prhone-log)\n[![prhone](https://img.shields.io/badge/prhone-project-1b38a9.svg)](http://romelperez.com)\n\n\u003e Simple JavaScript logger.\n\nA simple JavaScript logger for client side applications but it can be used in other environments. Supports [CommonJS](http://www.commonjs.org), [AMD](https://github.com/amdjs/amdjs-api) and standalone.\n\nSee [example.html](https://github.com/romelperez/prhone-log/blob/master/example.html) and [example.js](https://github.com/romelperez/prhone-log/blob/master/example.js) for browser and node.js usage respectively.\n\n## Install\n\nWebpack, Browserify and Node.js:\n\n```bash\nnpm install prhone-log\n```\n\nNPM CDN:\n\n```html\n\u003cscript src=\"https://unpkg.com/prhone-log\"\u003e\u003c/script\u003e\n```\n\nIn browser it is found as `window.prhone.Log`.\n\n## Use\n\n```js\nconst Log = require('prhone-log');\n\nconst log1 = new Log('app1');\n\nlog1.info('Initializing app');\nlog1.debug('Loading global configuration');\nlog1.debug('Loading user configuration');\n```\n\n...will output:\n\n```text\n18:31:55.987 INFO [app1] Initializing app\n18:31:55.987 DEBUG [app1] Loading global configuration\n18:31:55.988 DEBUG [app1] Loading user configuration\n```\n\n## API\n\n\n### **`Log`**\n\n#### **`logger Log(String namespace[, Object settings])`**\n\nCreates a new logger instance.\n\n- `String namespace` - The logger namespace or logger name.\n- `Object settings` - Optional configuration to overwrite.\n  - `Number priority` - Levels priority to display. Default to `3`. This can be used to display only messages equal or below than certain priority. (ex: `priority: 1` will only display warning and error messages.)\n  - `Boolean display` - Display messages on console. Default to `true`.\n  - `Boolean displayTime` - Display time (hh:mm:ss.SSS). Default to `true`.\n  - `Boolean displayLevel` - Display level name. Default to `true`.\n  - `Boolean displayNamespace` - Display namespace. Default to `true`.\n  - `Boolean throwErrors` - Throw errors on levels priority equal to 0. Default to `false`.\n  - `Boolean history` - Keep history. Default to `true`.\n  - `Boolean colors` - Display messages with colors. Default to `true`.\n\n| Level | Priority |\n| :---- | :------- |\n| error | 0        |\n| warn  | 1        |\n| info  | 2        |\n| debug | 3        |\n\n#### **`Object Log.COLORS`**\n\nList of colors to set up levels. Available colors: `RED`, `GREEN`, `YELLOW`, `BLUE`, `MAGENTA`, `CYAN`, `BLACK` and `WHITE`.\n\n#### **`Object Log.getSettings()`**\n\nGet a copy of the current global settings.\n\n#### **`Log.update(Object settingsToUpdate)`**\n\nUpdate the current global settings.\n\n#### **`Log.addLevel(Object level)`**\n\nAdds a new log level globally.\n\n- `Object level` - Level configuration.\n  - `String level.name` - Level name.\n  - `Number [level.priority]` - Priority value. Default to `3`.\n  - `Object [level.color]` - The log color definition. You can use the `Log.COLORS` references. Default `null`.\n    - `String browser` - Browser styles. Ex: `color:#2E7D32;`\n    - `String node` - Node.js color. Ex: `\\x1b[32m`.\n\nExample:\n\n```js\nconst Log = require('prhone-log');\n\nLog.addLevel({\n  name: 'fatal',\n  priority: 0,\n  color: Log.COLORS.RED\n});\n\nconst log2 = new Log('app2');\n\nconst errMsg = 'settings file is corrupt';\n\nlog2.fatal('The application crashed, details:', errMsg);\n// 20:02:50.753 FATAL [app2] The application crashed, details: settings file is corrupt\n```\n\n\n### **`logger`**\n\n#### **`logger.\u003c\u003cmethod\u003e\u003e(...parameters [, Object meta])`**\n\nCall a log level method, be it built in (`debug`, `info`, `warn`, `error`) or custom with parameters with any type (except functions). If the last parameter is an object or array it will be saved as metadata in history.\n\n```js\nconst logger = new Log('app1');\nlogger.info('This is a warning', { details: 'here the details' });\n// 18:20:15.985 INFO [app1] This is a warning\n```\n\n#### **`Array logger.getHistory()`**\n\nThis is an array with all messages recorded in order chronological, whether logged in console or not. Only if the setting `history` is enabled.\n\nThe format of each message is:\n\n`{`\n\n- `date`: The datetime in number format.\n- `level`: The string level name.\n- `text`: The parsed text message.\n- `meta`: The metadata if provided.\n\n`}`\n\n#### **`Object logger.getSettings()`**\n\nGet a copy of the current logger settings.\n\n#### **`logger.update(Object settingsToUpdate)`**\n\nUpdate the current logger settings.\n\n#### **`logger.addLevel(Object level)`**\n\nWorks the same way as `Log.addLevel()` method, but adds the level only to this logger.\n\n\n## Changelog\n\nRead [CHANGELOG.md](https://github.com/romelperez/prhone-log/blob/master/CHANGELOG.md) file to see changes.\n\n## License\n\n[MIT](https://github.com/romelperez/prhone-log/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromelperez%2Fprhone-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromelperez%2Fprhone-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromelperez%2Fprhone-log/lists"}