DEV Community

Cover image for The best alternative to the console.log statement
Patryk Rzucidło
Patryk Rzucidło

Posted on

The best alternative to the console.log statement

Beautiful Logger for Node.js: the best alternative to the console.log statement

🦒 Beautiful Logger for Node.js

The best alternative to the console.log statement

I love using console.log but it is difficult to record all the log information. I have implemented a small colored variant with tags, colors, messages of various errors and write to file logs in .json / txt format.

Resources: [NPM] [GITHUB]

💡 Features

  • [✔️] Easy to use
  • [✔️] MIT License
  • [✔️] 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
  • [✔️] Translations: 🇬🇧 🇮🇹 🇵🇱 (Help me ❤️)

👔 Screenshot

Beautiful Logger for Node.js

🚀 Installation

  1. In your node project run: npm install @ptkdev/logger --save
  2. Usage:
const Logger = require("@ptkdev/logger");
const logger = new Logger();
logger.info("message");
Enter fullscreen mode Exit fullscreen mode

You can set options to new Logger(options); example:

const Logger = require("@ptkdev/logger");

const options = {
    "language": "en",
    "colors": true,
    "debug": true,
    "info": true,
    "warning": true,
    "error": true,
    "sponsor": true,
    "write": true,
    "type": "log",
    "path": {
        "debug_log": "./debug.log",
        "error_log": "./errors.log",
    }
};

const logger = new Logger(options);
logger.info("message");
Enter fullscreen mode Exit fullscreen mode

Options

Parameter Description Values Default value
language Set language of log type en/it/pl en
colors Enable colors in terminal true/enabled/false/disabled true
debug Enable all logs with method debug true/enabled/false/disabled true
info Enable all logs with method info true/enabled/false/disabled true
warning Enable all logs with method warning true/enabled/false/disabled true
error Enable all logs with method errors true/enabled/false/disabled true
sponsor Enable all logs with method sponsor true/enabled/false/disabled true
write Write the logs into a file, you need set path values true/enabled/false/disabled false
type Format of logs in files log/json log
path If write is true, the library writes the logs to a path Object {"debug_log": "./debug.log", "error_log": "./errors.log"}

Methods

Method Description Parameters
debug(message, tag) message: Display debug log message
tag: prefix of message
message: string (mandatory)
tag: string (optional)
info(message, tag) message: Display info log message
tag: prefix of message
message: string (mandatory)
tag: string (optional)
warning(message, tag) message: Display warning log message
tag: prefix of message
message: string (mandatory)
tag: string (optional)
error(message, tag) message: Display errors log message
tag: prefix of message
message: string (mandatory)
tag: string (optional)
sponsor(message, tag) message: Display sponsor log message
tag: prefix of message
message: string (mandatory)
tag: string (optional)
stackoverflow(message, tag, error_string) message: Display stackoverflow log message
tag: prefix of message
error_string: query for stackoverflow, if empty we use message param
message: string (mandatory)
tag: string (optional)
error_string: string (optional)
docs(message, url, tag) message: Display docs log message
url: link of documentation
tag: prefix of message
message: string (mandatory)
url: string (optional)
tag: string (optional)

💫 License

  • Code and Contributions have MIT License
  • Images and logos have CC BY-NC 4.0 License (Freepik Premium License)
  • Documentations and Translations have CC BY 4.0 License

❤️ Thanks! Leave a feedback!

Latest comments (11)

Collapse
 
ttsoares profile image
Thomas TS

Just starting with Node... and this was my first dev tool :-).
Thanks !

Collapse
 
nivethsaran profile image
Niveth Saran

Looks really cool. I am gonna try this out right away!!!!

Collapse
 
ptkdev profile image
Patryk Rzucidło

Thanks bro!

Collapse
 
pnoeric profile image
Eric Mueller

Love it! Thanks for this. Just what I needed today for a project I'm working on.. some tasteful logging :-)

Collapse
 
ptkdev profile image
Patryk Rzucidło

Thanks for your donation! I really appreciated your kindness ❤️

Collapse
 
lyas777 profile image
lyas

Muy interesante :D

Collapse
 
igcp profile image
Igor Conde

Great! really cool tip thank's i will test soon

Collapse
 
voidp34r profile image
Matheus Rafael

great, i always use my own extended logger from another package, i offer to translate into my native language (pt-BR) and contribute to future improvements, i'm already joking a little to include in the next project 0 /

Collapse
 
code_regina profile image
Code_Regina

This is awesome! It seems to make development better. Thanks for the post!!

Collapse
 
thomasbnt profile image
Thomas Bnt ☕

I'm gonna test this 😄

Collapse
 
ptkdev profile image
Patryk Rzucidło

You are welcome!