Skip to content

Commit

Permalink
[Release] v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ptkdev committed May 24, 2020
1 parent ef93ee2 commit 70f775f
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 182 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
@@ -1,10 +1,15 @@
# v1.5.0 (May 20, 2020)
* Feature: logrotate
* Feature: palette: customize colors
# v1.6.0 (May 24, 2020)
* Fix: info color (default palette) changed from #2ECC71 to #4CAF50
* Fix: docs url with custom pallette
* Fix: stackoverflow url with custom pallette

[![](https://img.shields.io/badge/donate-paypal-005EA6.svg?logo=paypal)](https://www.paypal.me/ptkdev) [![](https://img.shields.io/badge/donate-patreon-F87668.svg?logo=patreon)](https://www.patreon.com/ptkdev) [![](https://img.shields.io/badge/donate-sponsors-ea4aaa.svg?logo=github)](https://github.com/sponsors/ptkdev/) [![](https://img.shields.io/badge/donate-ko--fi-29abe0.svg?logo=ko-fi)](https://ko-fi.com/ptkdev)


# v1.5.0 (May 20, 2020)
* Feature: logrotate
* Feature: palette: customize colors

# v1.4.0 (May 11, 2020)
* Translations: 🇫🇷 (Thanks: Sylvain Téchené)

Expand Down
72 changes: 67 additions & 5 deletions README.md
Expand Up @@ -2,7 +2,7 @@

# 🦒 Beautiful Logger for Node.js

[![](https://img.shields.io/badge/version-v1.5.0-lightgrey.svg)](https://github.com/ptkdev/ptkdev-logger/releases) [![](https://img.shields.io/npm/v/@ptkdev/logger.svg)](https://www.npmjs.com/package/@ptkdev/logger) [![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/ptkdev/ptkdev-logger/blob/master/LICENSE.md) [![](https://img.shields.io/badge/ES-9-F7DF1E.svg)](https://wikipedia.org/wiki/ECMAScript) [![](https://snyk.io/test/github/ptkdev/ptkdev-logger/badge.svg)](https://snyk.io/test/github/ptkdev/ptkdev-logger) [![](https://discordapp.com/api/guilds/383373985666301975/embed.png)](http://discord.ptkdev.io)
[![](https://img.shields.io/badge/version-v1.6.0-lightgrey.svg)](https://github.com/ptkdev/ptkdev-logger/releases) [![](https://img.shields.io/npm/v/@ptkdev/logger.svg)](https://www.npmjs.com/package/@ptkdev/logger) [![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/ptkdev/ptkdev-logger/blob/master/LICENSE.md) [![](https://img.shields.io/badge/ES-9-F7DF1E.svg)](https://wikipedia.org/wiki/ECMAScript) [![](https://snyk.io/test/github/ptkdev/ptkdev-logger/badge.svg)](https://snyk.io/test/github/ptkdev/ptkdev-logger) [![](https://discordapp.com/api/guilds/383373985666301975/embed.png)](http://discord.ptkdev.io)

> The best alternative to the console.log statement
Expand All @@ -21,6 +21,7 @@
- - 🧰 [Options](#-options)
- - 🔌 [Methods](#-methods)
- - 🎨 [Palette](#-palette)
- - 🤹‍♂️ [LogRotate](#-logrotate)
- 👨‍💻 [Contributing](#-contributing)
- 🐛 [Known Bugs](https://github.com/ptkdev/ptkdev-logger/issues?q=is%3Aopen+is%3Aissue+label%3Abug)
- 🍻 Community:
Expand All @@ -30,7 +31,7 @@
* [✔️] Easy to use
* [✔️] MIT License
* [✔️] Palette (🎨 Customize colors)
* [✔️] Logrotate
* [✔️] Logrotate 🤹‍♂️
* [✔️] The best alternative to the console.log statement
* [✔️] Write stdout logs to file (supported format: text/log and json)
* [✔️] The JSON logs format is compatible with [pinojs](https://github.com/pinojs/pino)
Expand Down Expand Up @@ -66,7 +67,7 @@ const options = {
"size": "10M",
"encoding": "utf8"
},
"path": { // remember: add logs folder or files to .gitignore
"path": { // remember: add string *.log to .gitignore
"debug_log": "./debug.log",
"error_log": "./errors.log",
}
Expand All @@ -92,7 +93,7 @@ See folder `examples`, run with `node example.js`. Below is available a descript
| write | Write the logs into a file, you need set path values | true / enabled / false / disabled | false | **v1.0.0** |
| type | Format of logs in files | log / json | log | **v1.0.0** |
| rotate | Rotates the log files when size exceeds this value | `10B` / `10K` / `10M` / `10G` | `"rotate": {"size": "10M"}` | **v1.5.0** |
| palette | Change palette with hexcode colors | `{ "palette": { "info": { "label": "#ffffff", "text": "#4CAF50", "background": "#4CAF50" } }` | default palette | **v1.5.0** |
| palette | Change palette with hexcode colors | [Object](#-palette) | default palette | **v1.5.0** |
| path | If write is true, the library writes the logs to a path | Object | `{"debug_log": "./debug.log", "error_log": "./errors.log"}` | **v1.0.0** |

## 🔌 Methods
Expand All @@ -111,13 +112,74 @@ See folder `examples`, run with `node example.js`. Below is available a descript

[![Beautiful Logger for Node.js](https://raw.githubusercontent.com/ptkdev/ptkdev-logger/nightly/.github/assets/screenshot/ptkdev-logger-palette.png)](https://raw.githubusercontent.com/ptkdev/ptkdev-logger/nightly/.github/assets/screenshot/ptkdev-logger-palette.png)

You can customize palette colors with `options.palette` with hexcode values.
You can customize palette colors with Object `palette` and with hexcode values.
- `label` is text on left (INFORMATION / ERROR / DOCS, etc..)
- `text` is message of log on right
- `background` is background color on left side

```json
{
...
"palette": {
"info": { // method name
"label": "#ffffff", // label on left
"text": "#4CAF50", // log message
"background": "#4CAF50" // background
},
"warning": {
"label": "#ffffff",
"text": "#FF9800",
"background": "#FF9800"
},
"error": {
"label": "#ffffff",
"text": "#FF5252",
"background": "#FF5252"
},
"stackoverflow": {
"label": "#ffffff",
"text": "#9C27B0",
"background": "#9C27B0"
},
"docs": {
"label": "#ffffff",
"text": "#FF4081",
"background": "#FF4081"
},
"debug": {
"label": "#ffffff",
"text": "#1976D2",
"background": "#1976D2"
},
"sponsor": {
"label": "#ffffff",
"text": "#607D8B",
"background": "#607D8B"
},
"time": {
"label": "#ffffff",
"background": "#795548"
}
}
...
}
```

See folder `examples`, run with `node example.js`.

## 🤹‍♂️ LogRotate

Rotates the file when size exceeds 10 megabytes (optional, default 10M - values: 10B (byte) / 10K (kilobyte)/ 10M (megabyte)/ 10G (gigabyte))

```json
...
"rotate": {
"size": "10M",
"encoding": "utf8"
},
...
```

## 📚 Documentation
Run `npm run docs`

Expand Down
4 changes: 2 additions & 2 deletions examples/example.js
Expand Up @@ -30,8 +30,8 @@ const options = {
"palette": {
"info": {
"label": "#ffffff", // label on left
"text": "#4CAF50", // log message
"background": "#4CAF50" // background
"text": "#2ECC71", // log message
"background": "#2ECC71" // background
},
"warning": {
"label": "#ffffff",
Expand Down
12 changes: 8 additions & 4 deletions modules/logger.js
Expand Up @@ -365,8 +365,10 @@ class Log {
*
*/
docs(message = "", url = "", tag = "") {
this.log(this.TYPES_LOG.DOCS, tag, `${message} - ${chalk.rgb(236, 135, 191).underline.italic(url)}`);
this.appendFile(this.TYPES_LOG.DOCS, tag, `${message} - ${chalk.rgb(236, 135, 191).underline.italic(url)}`);
let docs = this.TYPES_LOG.DOCS;

this.log(this.TYPES_LOG.DOCS, tag, `${message} - ${docs.color.underline.italic(url)}`);
this.appendFile(this.TYPES_LOG.DOCS, tag, `${message} - ${docs.color.underline.italic(url)}`);
}

/**
Expand All @@ -384,9 +386,11 @@ class Log {
error_message = message;
}

let stackoverflow = this.TYPES_LOG.STACKOVERFLOW;

let url = `https://stackoverflow.com/search?q=${encodeURI(error_message)}`;
this.log(this.TYPES_LOG.STACKOVERFLOW, tag, `${message} - ${chalk.rgb(41, 128, 185).underline.italic(url)}`);
this.appendFile(this.TYPES_LOG.STACKOVERFLOW, tag, `${message} - ${chalk.rgb(41, 128, 185).underline.italic(url)}`);
this.log(this.TYPES_LOG.STACKOVERFLOW, tag, `${message} - ${stackoverflow.color.underline.italic(url)}`);
this.appendFile(this.TYPES_LOG.STACKOVERFLOW, tag, `${message} - ${stackoverflow.color.underline.italic(url)}`);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/types.js
Expand Up @@ -12,7 +12,7 @@
const chalk = require("chalk");

module.exports = {
INFO: {id: "INFO", label: " | INFORMATION ", bgcolor: chalk.bgRgb(46, 204, 113).white.bold, color: chalk.rgb(46, 204, 113)},
INFO: {id: "INFO", label: " | INFORMATION ", bgcolor: chalk.bgRgb(76, 175, 80).white.bold, color: chalk.rgb(76, 175, 80)},
WARNING: {id: "WARNING", label: " | WARNING ", bgcolor: chalk.bgRgb(243, 156, 18).white.bold, color: chalk.rgb(243, 156, 18)},
ERROR: {id: "ERROR", label: " | ERROR ", bgcolor: chalk.bgRgb(192, 57, 43).white.bold, color: chalk.rgb(192, 57, 43)},
DEBUG: {id: "DEBUG", label: " | DEBUG ", bgcolor: chalk.bgRgb(155, 89, 182).white.bold, color: chalk.rgb(155, 89, 182)},
Expand Down

0 comments on commit 70f775f

Please sign in to comment.