A Lightweight color logging package for Nodejs.
- π Beautifully add colors and background colors log messages.
- π Display current timestamp of log message.
- π Supports log levels (success, info, warning, error).
- β‘ Typing effect on logging.
Install tonelog using npm:
npm i tonelog
Warning!. Tonelog has recently undergone a major refactor: version ^2.0.0.
The code below which worked on older versions like 1.1.7 downwards is now deprecated.
const tonelog = require("tonelog"); tonelog("error", "This function is now deprecated");
But you could still use the "tonelog" function on recent versions, you'll have to require "tonelog" as a function.
const { tonelog } = require("tonelog")
const { tone } = require("tonelog"); console.log(tone.cyan("This is a cyan colored message")); console.log(tone.bright_cyan("This is a bright cyan colored message")); console.log(tone.bg_cyan("This is a background cyan colored message"));
- success
- info
- warning
- error
- reset
- red
- green
- yellow
- blue
- purple
- cyan
- white
- bright_red
- bright_green
- bright_yellow
- bright_blue
- bright_purple
- bright_cyan
- bright_white
- bg_black
- bg_red
- bg_green
- bg_yellow
- bg_blue
- bg_purple
- bg_cyan
- bg_white
- orange
- pink
- sky_blue
- brown
- teal
- lavender
- maroon
- olive
- indigo
- gold
- silver
- turquoise
- coral
- lilac
- mint_green
- mustard
- salmon
- chocolate_brown
- pale_pink
- deep_purple
Add timestamp to log message with "UseTimestamp".
const { useTimestamp } = require("tonelog"); console.log(useTimestamp("A log message with the current timestamp"));
Logging message according to it's level
const { toneLevel } = require("tonelog"); console.log(toneLevel.error("This is an error level log message"));
Log levels supported by tonelog.
- success
- info
- warning
- error
Make your log message more descriptive by adding timestamp with log level
const { useTimestamp, toneLevel } = require("tonelog"); console.log(useTimestamp(toneLevel.success("Success message")));
"typed" function simulates a typing effect on the terminal or console, as a cool way to log messages.
This function takes in 4 parameters which are: strings, delay, typespeed and backspeed.
const { typed } = require("tonelog"); const myArray = [ "This is the first string on the array", "This is the second string on the array", "This is the third string on the array", ]; typed( myArray, // Strings: Array of strings to type. 1000, // Delay: Duration before starting to type. 70, // Typespeed: Speed of typing characters in miliseconds. 50 // Backspeed: Speed of backspacing characters in miliseconds.
- To log a message after typing is complete...
It is recommended to use "typed" inside of an async function as shown below.
const { typed } = require("tonelog"); const typing = async () => { const myArray = [ "This is the first string on the array", "This is the second string on the array", "This is the third string on the array", ]; // Typing... await typed(myArray, 1000, 70, 50); console.log("Typing is complete"); }; // Call the function typing();
Alternatively you can use ".finally() or .then()" methods:
- Since the "typed" function return a promise, using ".finally() or .then()" is a also great way to handle this.
const { typed } = require("tonelog"); const myArray = [ "This is the first string", "This is the second string", "This is the third string", ]; typed(myArray, 1000, 70, 50).finally(() => { console.log("Typing is complete"); });
The same goes with ".then()"
Help make Tonelog better.
If there is a feature you wish to add, please send us a pull request; Feel free to contribute, report issues, or provide feedback!
Enjoy logging with Tonelog! π¨
Copyright Β© 2023 Dieke Sydney. Licensed under the MIT License.