Loglow is a flexible logging utility for Node.js, designed to enhance your console output with customizable colors, styles, and timestamps. It's perfect for developers looking for more than just the standard logging capabilities.
To install Loglow, run the following command in your Node.js project:
npm i loglow --save-dev
Loglow enables you to log messages to the console using the add
method followed by the print
method.
new Loglow().add('Hello, world!').print();
// Output: Hello, world!
Loglow allows you to add different colors and styles to your log messages.
new Loglow()
.add(LogColor.Red, 'Error: Something went wrong.')
.print();
// Output: Error: Something went wrong. <-- (in red)
Also, Loglow supports multiple colors and styles for a single message.
new Loglow()
.add(LogColor.Red, LogStyle.Bold, 'Error: Something went wrong.')
.print();
// Output: Error: Something went wrong. <-- (in bold red)
Loglow can automatically add timestamps to your log messages using the addTimestamp
method.
new Loglow()
.addTimestamp()
.add('Hello, world!')
.print();
// Output: 2021-01-01T12:00:00Z Hello, world!
Loglow also allows you tou customize the timestamp color or style.
new Loglow()
.addTimestamp(LogColor.Cyan)
.print();
// Output: 2021-01-01T12:00:00Z <-- (in cyan)
Loglow provides the addNewLine
method to add new lines to your log messages.
new Loglow()
.add('First line.')
.addNewLine()
.add('Second line.')
.print();
// Output: First line.
// Second line.
Loglow methods can be chained together to create complex log messages.
new Loglow()
.addTimestamp()
.add(LogColor.Green, 'Success: Operation completed.')
.addNewLine()
.add(LogColor.Blue, LogStyle.Reverse, 'Details: ')
.addNewline()
.add('- Item 1')
.addNewLine()
.add('- Item 2')
.print();
// Output: 2021-01-01T12:00:00Z Success: Operation completed. <-- (in green)
// Details: <-- (in reverse blue)
// - Item 1
// - Item 2
Loglow provides a set of predefined colors and styles that can be used to customize the output. Here's a list of available colors and styles:
LogColor.Red
LogColor.Green
LogColor.Yellow
LogColor.Blue
LogColor.Magenta
LogColor.Cyan
LogColor.White
LogStyle.Reset
- Resets the style to the defaultLogStyle.Bold
- Makes the text boldLogStyle.Dim
- Makes the text dimLogStyle.Italic
- Makes the text italicLogStyle.Underscore
- Underlines the textLogStyle.Blink
- Makes the text blinkLogStyle.Reverse
- Reverses the foreground and background colors
That's it! I hope you find Loglow useful for your Node.js projects!