0.17.811 • Published 7 years ago

pepper-log v0.17.811

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

Pepper Log

GitHub license npm Version 0.17.810 GitHub issues

Terminal Screenshot

Contains some necessary console logging functionalities for you so you could focus more on what's important - building awesome apps.

Installation

npm install pepper-log

What's in the box?

  • Timestamp - Basically, you should know when the log occured.
  • Basic Colors - An effective attention grabber for important matters.
  • Headers - Useful when creating sections.
  • Separator Lines - Quickly generate line separators with a single function call.
  • Indention - Useful for nested logs.

Usage

Sample code

var log = require('pepper-log');

log.setLineChar('=');
log.endl()
   .header('Pepper.IO Industries')
   .out('Thank you for using Pepper Log!')
   .out('Version 0.17.810\n')
   .plain('Simple to use library for basic console logging.')
   .plain('Run `npm install pepper-log` to use this package.')
   .plain('Import it to your code using `var log = require("pepper-log");`')
   .line('-')
   .info('Loading components...', 'Pepper Log: ', true)
   .ok('Network module loaded.')
   .ok('Compression module loaded.')
   .ind(2).info('Using gzip compression.')
   .ok('Display module loaded.')
   .ind(2).warn('The display supports only 256 colors.')
   .ind(2).err('No compatible graphics driver detected.')
   .line().showDate()
   .ok('All systems operational.', '', true).endl();

Import the package to your code

var log = require('pepper-log');

No timestamp output

SyntaxDescription
log.out(message)Basically a console.log call, but shorter (if your require variable is short, that is).
log.out('Hello, world!');
// → Hello, world!

Timestamped output

SyntaxDescription
log.plain(message)Produces a console output with timestamp with "plain" status.
log.showDate(bool)By default, the system time will only be shown on a timestamped output. Succeeding timestamped logs will be affected.
log.plain('Hey, something just happened.');
// → [15:33:04] Hey, something just happened.

log.showDate(true);
log.plain('Hey, something just happened.');
// → [8/11/17 16:14:38] Hey, something just happened.

Common status logs

Also a timestamped output, but with extra status message and colors.

StatusSyntaxColorDescription
OKlog.ok(message)GreenAsserts an affirmative tone to your message.
Infolog.info(message)BlueFor gentle reminders.
Warninglog.warn(message)YellowUsed for cautions or for requesting close attention.
Errorlog.err(message)RedFor errors or critial events that needs immediate response from the user.
log.info('Thanks for using Pepper Log!');
log.ok('The program exited with a 0 status.');
log.warn('You\'re using a deprecated version of this package. Please consider updating.');
log.err('Cannot divide by 0.');

// → [12:28:06] Info: Thanks for using Pepper Log!
// → [12:28:06] OK: The program exited with a 0 status.
// → [12:28:06] Warning: You're using a deprecated version of this package. Please consider updating.
// → [12:28:06] Error: Cannot divide by 0.

By default, the color is applied from the timestamp until the colon (:) of the status message. Your message will use the default terminal color.

If you want to apply the status' color to the whole line, you may need to set the second optional parameter to true. The first optional parameter gives you the ability to customize the status message.

log.ok|info|warn|err(message [, status = 'Info: ' [, colorline = false]])

Optional ArgDescription
statusThe status message.
colorlineDetermines if the whole line should be colored.
log.ok('Complete.', 'Download Daemon: ');
log.info('The blue color also affects this text.', 'Blueify: ', true);
log.warn('I use the default status message and the color spans up to this point.', undefined, true);

// → [06:45:42] Download Daemon: Complete.
// → [06:45:42] Blueify: The blue color also affects this text.
// → [06:45:42] Warning: I use the default status message and the color spans up to this point.

Line separators

Draw a horizontal line. By default, it uses the dash "-" character.

log.line([char = '-' [, width = default_width]])

Optional ArgDescription
charThe character to use for drawing the line. Dash "-" is set as default.
widthThe width/length of the line in characters.
log.line();
log.line('=');
log.line(undefined, 12);

// → ------------------------------
// → ==============================
// → ------------

The global line width is set to 30. To change it:

log.setLineWidth([number = 30])

You can also change the global line character:

log.setLineChar([char = '-'])

log.setLineWidth(18);
log.setLineChar('+');
log.line();

// → ++++++++++++++++++

Headers

Useful for creating sections. The header caption/text is separated by top and bottom lines that use the line() function, thus the global line width and character affects the header lines.

SyntaxDescription
log.heading(caption [, margin = 0 [, padding = 0]])Outputs the caption

Optional Arguments

Optional ArgDescription
marginThe no. of lines outside the header lines.
paddingThe no. of lines from the header text to the header lines.
log.header("Contributions and credits");
log.out('Some text before.');
log.setLineWidth(40);
log.header('A wide header', 1, 2);
log.out('Some text after.');

// → ------------------
// → Contributions and credits
// → ------------------
// → Some text before.
// → 
// → ----------------------------------------
// → 
// → 
// → A wide header
// → 
// → 
// → ----------------------------------------
// → 
// → Some text after.

Empty line

Output an empty line or to give some space between logs.

log.endl([lines = 1])

Optional ArgDescription
linesThe number of empty lines to output.
log.endl(4);

// →
// →
// →
// →

Indention

Need hierarchy logs? You can indent logs using the ind() function. By default, it uses two spaces (' ') as the indent/tab character.

log.ind([indent_count = 1 [, indent_char = m_indentchar]])

Optional ArgDescription
indent_countHow many times the indent will be applied.
indent_charThe character to be used to indent the output.

*Note: The indent will only be applied to the next output.*

log.info('Starting services...');
log.ind(2);
log.ok('Service 1 started.');
log.ind(2);
log.ok('Service 2 started.');
log.info('All services started successfully.');
log.warn('Service 1 is experiencing a heavy traffic.');
log.ind(2, '>>');
log.plain('Service 1 is now running on priority mode.');

// → [03:39:51] Info: Starting services...
// →   [03:39:51] OK: Service 1 started.
// →   [03:39:51] OK: Service 2 started.
// → [03:39:51] Info: All services started successfully.
// → [03:39:51] Warning: Service 1 is experiencing a heavy traffic.
// → >>>>[03:39:51] Service 1 is now running on priority mode.

Chaining

You can immediately call another Pepper Log function after the previous one.

log.header('Pepper.IO Industries')
   .plain('Loading components...');

// → ------------------------------
// → Pepper.IO Industries
// → ------------------------------
// → [14:05:06] Loading components...