Skip to content

Commit

Permalink
[Release] v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ptkdev committed May 6, 2020
1 parent f4ec79c commit 3440cc2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 131 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,5 +1,6 @@
# v1.1.3 (May 05, 2020)
# v1.2.0 (May 06, 2020)
* Fix: security patch
* Translations: 馃嚜馃嚫 馃嚨馃嚬 (Thanks: Bruno Kummel)

[![](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)

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

# 馃 Beautiful Logger for Node.js

[![](https://img.shields.io/badge/version-v1.1.3-lightgrey.svg)](https://github.com/ptkdev/ptkdev-logger/releases) [![](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.2.0-lightgrey.svg)](https://github.com/ptkdev/ptkdev-logger/releases) [![](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 @@ -29,7 +29,7 @@
* [鉁旓笍] 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)
* [鉁旓笍] Translations: 馃嚞馃嚙 馃嚠馃嚬 馃嚨馃嚤 (Help me 鉂わ笍)
* [鉁旓笍] Translations: 馃嚞馃嚙 馃嚠馃嚬 馃嚨馃嚤 馃嚜馃嚫 馃嚨馃嚬 (Help me 鉂わ笍)

## 馃憯 Screenshot
[![Beautiful Logger for Node.js](https://raw.githubusercontent.com/ptkdev/ptkdev-logger/nightly/.github/assets/screenshot/ptkdev-logger-screen1.png)](https://raw.githubusercontent.com/ptkdev/ptkdev-logger/nightly/.github/assets/screenshot/ptkdev-logger-screen1.png)
Expand Down
158 changes: 34 additions & 124 deletions modules/logger.js
Expand Up @@ -24,20 +24,16 @@ const logger = console;
let Types = require("./types");

class Log {
constructor(options = new Object()) {
if (
typeof options.language === "undefined" ||
options.language === null
) {
constructor(options = new Object) {
if (typeof options.language === "undefined" || options.language === null) {
options.language = "en";
} else {
Types.INFO.label = languages[options.language]["INFO"];
Types.WARNING.label = languages[options.language]["WARNING"];
Types.ERROR.label = languages[options.language]["ERROR"];
Types.DEBUG.label = languages[options.language]["DEBUG"];
Types.DOCS.label = languages[options.language]["DOCS"];
Types.STACKOVERFLOW.label =
languages[options.language]["STACKOVERFLOW"];
Types.STACKOVERFLOW.label = languages[options.language]["STACKOVERFLOW"];
Types.SPONSOR.label = languages[options.language]["SPONSOR"];
}

Expand All @@ -53,10 +49,7 @@ class Log {
options.info = true;
}

if (
typeof options.warning === "undefined" ||
options.warning === null
) {
if (typeof options.warning === "undefined" || options.warning === null) {
options.warning = true;
}

Expand All @@ -70,21 +63,12 @@ class Log {

if (typeof options.write === "undefined" || options.write === null) {
options.write = false;
} else if (
typeof options.path === "undefined" ||
options.path === null
) {
if (
typeof options.debug_log === "undefined" ||
options.debug_log === null
) {
} else if (typeof options.path === "undefined" || options.path === null) {
if (typeof options.debug_log === "undefined" || options.debug_log === null) {
options.debug_log = "./debug.log";
}

if (
typeof options.error_log === "undefined" ||
options.error_log === null
) {
if (typeof options.error_log === "undefined" || options.error_log === null) {
options.error_log = "./errors.log";
}
}
Expand All @@ -104,20 +88,18 @@ class Log {
*
*/
current_time(format = "string") {
let tz_offset = new Date().getTimezoneOffset() * 60000;
let tz_offset = (new Date()).getTimezoneOffset() * 60000;

if (format === "json") {
return new Date(Date.now() - tz_offset).toISOString();
return (new Date(Date.now() - tz_offset)).toISOString();
}

if (format === "timestamp") {
return new Date(Date.now() - tz_offset).getTime();
return (new Date(Date.now() - tz_offset)).getTime();
}

return new Date(Date.now() - tz_offset)
.toISOString()
.slice(0, -5)
.replace("T", " ");
return (new Date(Date.now() - tz_offset)).toISOString().slice(0, -5).replace("T", " ");

}

/**
Expand All @@ -135,30 +117,20 @@ class Log {
if (tag !== "") {
tag = `${tag}: `;
}
let log_text = `[${this.current_time()}] [${
type.id
}] ${tag}${message}\n`;

fse.appendFile(
this.config.path.debug_log,
ansi(log_text),
err => {
if (err) {
logger.log(err);
}
let log_text = `[${this.current_time()}] [${type.id}] ${tag}${message}\n`;

fse.appendFile(this.config.path.debug_log, ansi(log_text), (err) => {
if (err) {
logger.log(err);
}
);
});

if (type.id === "ERROR") {
fse.appendFile(
this.config.path.error_log,
ansi(log_text),
err => {
if (err) {
logger.err(err);
}
fse.appendFile(this.config.path.error_log, ansi(log_text), (err) => {
if (err) {
logger.err(err);
}
);
});
}
} else {
const debug_adapter = new FileSync(this.config.path.debug_log);
Expand Down Expand Up @@ -188,30 +160,10 @@ class Log {
debug_db.defaults({logs: []}).write();
error_db.defaults({logs: []}).write();

debug_db
.get("logs")
.push({
level: level,
time: this.current_time("timestamp"),
date: this.current_time("json"),
msg: ansi(message),
tag: ansi(tag),
v: 1
})
.write();
debug_db.get("logs").push({level: level, time: this.current_time("timestamp"), date: this.current_time("json"), msg: ansi(message), tag: ansi(tag), v: 1}).write();

if (type.id === "ERROR") {
error_db
.get("logs")
.push({
level: level,
time: this.current_time("timestamp"),
date: this.current_time("json"),
msg: ansi(message),
tag: ansi(tag),
v: 1
})
.write();
error_db.get("logs").push({level: level, time: this.current_time("timestamp"), date: this.current_time("json"), msg: ansi(message), tag: ansi(tag), v: 1}).write();
}
}
}
Expand All @@ -233,21 +185,9 @@ class Log {
tag = ` ${tag}:`;
}
if (this.config.colors === "enabled" || this.config.colors === true) {
logger.log(
chalk`${type.bgcolor(type.label)}${time.bgcolor(
` ${this.current_time()} `
)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`
);
logger.log(chalk`${type.bgcolor(type.label)}${time.bgcolor(` ${this.current_time()} `)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`);
} else {
logger.log(
ansi(
chalk`${type.bgcolor(type.label)}${time.bgcolor(
` ${this.current_time()} `
)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(
message
)}`
)
);
logger.log(ansi(chalk`${type.bgcolor(type.label)}${time.bgcolor(` ${this.current_time()} `)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`));
}
}

Expand All @@ -267,21 +207,9 @@ class Log {
tag = ` ${tag}:`;
}
if (this.config.colors === "enabled" || this.config.colors === true) {
logger.error(
chalk`${type.bgcolor(type.label)}${time.bgcolor(
` ${this.current_time()} `
)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`
);
logger.error(chalk`${type.bgcolor(type.label)}${time.bgcolor(` ${this.current_time()} `)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`);
} else {
logger.error(
ansi(
chalk`${type.bgcolor(type.label)}${time.bgcolor(
` ${this.current_time()} `
)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(
message
)}`
)
);
logger.error(ansi(chalk`${type.bgcolor(type.label)}${time.bgcolor(` ${this.current_time()} `)}${type.bgcolor(" ")}${type.color(tag)} ${type.color(message)}`));
}
}

Expand Down Expand Up @@ -360,16 +288,8 @@ class Log {
*
*/
docs(message = "", url = "", tag = "") {
this.log(
this.TYPES_LOG.DOCS,
tag,
`${message} - ${chalk.rgb(236, 135, 191).underline.italic(url)}`
);
this.append_file(
this.TYPES_LOG.DOCS,
tag,
`${message} - ${chalk.rgb(236, 135, 191).underline.italic(url)}`
);
this.log(this.TYPES_LOG.DOCS, tag, `${message} - ${chalk.rgb(236, 135, 191).underline.italic(url)}`);
this.append_file(this.TYPES_LOG.DOCS, tag, `${message} - ${chalk.rgb(236, 135, 191).underline.italic(url)}`);
}

/**
Expand All @@ -387,19 +307,9 @@ class Log {
error_message = message;
}

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.append_file(
this.TYPES_LOG.STACKOVERFLOW,
tag,
`${message} - ${chalk.rgb(41, 128, 185).underline.italic(url)}`
);
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.append_file(this.TYPES_LOG.STACKOVERFLOW, tag, `${message} - ${chalk.rgb(41, 128, 185).underline.italic(url)}`);
}

/**
Expand All @@ -417,4 +327,4 @@ class Log {
}
}

module.exports = Log;
module.exports = Log;
4 changes: 2 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "@ptkdev/logger",
"description": "Beautiful Logger for Node.js: the best alternative to the console.log statement",
"version": "1.1.3",
"version": "1.2.0",
"main": "modules/logger.js",
"author": "Patryk Rzucid艂o [@ptkdev] <support@ptkdev.io> (https://ptk.dev)",
"license": "MIT",
Expand Down Expand Up @@ -79,6 +79,6 @@
},
"contributors": [
"Ilua Chubarov [@Ilya] <agoalofalife@gmail.com> (https://github.com/agoalofalife)",
"Bruno Kummel <kummel@gmail.com> (https://github.com/Bruck1701)"
"Bruno Kummel [@Bruck1701] <kummel@gmail.com> (https://github.com/Bruck1701)"
]
}
2 changes: 1 addition & 1 deletion translations/es.js
Expand Up @@ -10,7 +10,7 @@
*
* Param: don't translate words between ## ##, example: ##ciao##
*
* @contributors: Bruno Kummel
* @contributors: Bruno Kummel [@Bruck1701] <kummel@gmail.com> (https://github.com/Bruck1701)
*
* @license: CC BY 4.0 License
*
Expand Down
2 changes: 1 addition & 1 deletion translations/pt.js
Expand Up @@ -10,7 +10,7 @@
*
* Param: don't translate words between ## ##, example: ##ciao##
*
* @contributors: Bruno Kummel
* @contributors: Bruno Kummel [@Bruck1701] <kummel@gmail.com> (https://github.com/Bruck1701)
*
* @license: CC BY 4.0 License
*
Expand Down

0 comments on commit 3440cc2

Please sign in to comment.