# pepper-log

> A simple console logging utility for node.js.

Latest version **0.17.811** (published 2017-08-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install pepper-log
pnpm add pepper-log
yarn add pepper-log
bun add pepper-log
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.17.811 |
| Published | 2017-08-11 |
| First published | 2017-08-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | John Espiritu, Cloud Cheetah |
| Maintainers | hkri |
| Keywords | log, logging, pepper-log, console, console-log, debugging |

## Links

- npm: https://www.npmjs.com/package/pepper-log
- Repository: https://pepperice@github.com/pepperice/pepper-log
- Homepage: https://github.com/pepperice/pepper-log#readme
- Issues: https://github.com/pepperice/pepper-log/issues
- npm.io page: https://npm.io/package/pepper-log

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^2.1.0
- [moment](https://npm.io/package/moment.md) ^2.18.1
- [sprintf-js](https://npm.io/package/sprintf-js.md) ^1.1.1

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.17.811 (latest) — 2017-08-11

## README

# Pepper Log

[![GitHub license](https://img.shields.io/badge/license-MIT-green.svg)](https://raw.githubusercontent.com/pepperice/pepper-log/master/LICENSE)
[![npm](https://img.shields.io/npm/v/npm.svg)](https://github.com/pepperice/pepper-log)
![Version 0.17.810](https://img.shields.io/badge/version-0.17.810-orange.svg)
[![GitHub issues](https://img.shields.io/github/issues/pepperice/pepper-log.svg)](https://github.com/pepperice/pepper-log/issues)

![Terminal Screenshot](/media/terminal.png)

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

```js
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
```js
var log = require('pepper-log');
```

#### No timestamp output

Syntax | Description
--- | ---
`log.out(message)` | Basically a `console.log` call, but shorter (if your require variable is short, that is).

```js
log.out('Hello, world!');
// → Hello, world!
```

### Timestamped output

Syntax | Description
--- | ---
`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.

```js
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.

Status | Syntax | Color | Description
--- | --- | --- | ---
OK | `log.ok(message)` | Green | Asserts an affirmative tone to your message.
Info | `log.info(message)` | Blue | For gentle reminders.
Warning | `log.warn(message)` | Yellow | Used for cautions or for requesting close attention.
Error | `log.err(message)` | Red | For errors or critial events that needs immediate response from the user.

```js
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 Arg | Description
--- | ---
`status` | The status message.
`colorline` | Determines if the whole line should be colored.

```js
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 Arg | Description
--- | ---
`char` | The character to use for drawing the line. Dash "-" is set as default.
`width` | The width/length of the line in characters.

```js
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 = '-'])`

```js
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.

Syntax | Description
--- | ---
`log.heading(caption [, margin = 0 [, padding = 0]])` | Outputs the caption

#### Optional Arguments

Optional Arg | Description
--- | ---
`margin` | The no. of lines outside the header lines.
`padding` | The no. of lines from the header text to the header lines.

```js
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 Arg | Description
--- | ---
`lines` | The number of empty lines to output.

```js
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 Arg | Description
--- | ---
`indent_count` | How many times the indent will be applied.
`indent_char` | The character to be used to indent the output.

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

```js
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.

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

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

---
_Source: https://npm.io/package/pepper-log · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
