# vorpal-log

> Logging/Printing utility for vorpal.

Latest version **1.1.0** (published 2016-01-08) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2016-01-08 |
| First published | 2015-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Aljoscha Meyer |
| Maintainers | aljoscha-meyer |
| Keywords | vorpal, cli, log |

## Links

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

## Dependencies (1)

- [chalk](https://npm.io/package/chalk.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

- 1.1.0 (latest) — 2016-01-08
- 1.0.1 — 2015-11-02
- 1.0.0 — 2015-10-14
- 0.0.3 — 2015-10-10
- 0.0.2 — 2015-10-10
- 0.0.1 — 2015-10-10

## README

# Vorpal - Log

[![Build Status](https://travis-ci.org/AljoschaMeyer/vorpal-log.svg)](https://travis-ci.org/AljoschaMeyer/vorpal-log)

A [Vorpal.js](https://github.com/dthree/vorpal) extension adding simple logging methods.

### Installation

```bash
npm install vorpal-log
npm install vorpal
```

### Getting Started

```js
const vorpal = (require('vorpal'))();
const vorpalLog = require('vorpal-log');

vorpal.use(vorpalLog)
  .delimiter('vorpal-log demo $')
  .show();

const logger = vorpal.logger;

vorpal.command('log')
  .action(function(args, cb) {
  logger.debug('Log command called without arguments.');
  logger.log('Foo, bar, baz!');
  logger.confirm('You successfully ran the log command.');
  logger.info('It logs stuff.');
  logger.warn('Careful with that axe, Eugene!');
  logger.error('Something went wrong...');
  logger.fatal('If this was a real program, it would probably shut down now.');
  cb();
});

logger.info('This is a demo program for the vorpal-log extension.');
logger.info('Run log to produce some output.');
logger.info('Run loglevel <level> to change the level, e.g. \'loglevel warn\'');
```

### Default Functionality

Vorpal-log comes with the following predefined methods for logging:

- `logger.debug(msg)` (loglevel 10)
- `logger.log(msg)` (loglevel 20)
- `logger.info(msg)` (loglevel 20)
- `logger.confirm(msg)` (loglevel 20)
- `logger.warn(msg)` (loglevel 30)
- `logger.error(msg)` (loglevel 40)
- `logger.fatal(msg)` (loglevel 50)

`logger.printMsg(msg)` will always print the message without caring about the loglevel or formatting.

Set the loglevel:

`logger.setFilter(level)`

E.g. `logger.setFilter('warn')` will only print messages via logger.warn, logger.error and logger.fatal.

#### Options

The following options passed by `vorpal.use(vorpalLogger, options)` are used:

- `printDate`: If this is true, the default formatters begin each message with the current date.
- `preformat`: a function which is passed the message and which returns a string which should be logged instead by the default formatters. Could for example be used to render [marked](https://github.com/mikaelbr/marked-terminal).

#### Commands

Vorpal-log adds the following (hidden) command, which simply delegates to `logger.setFilter`. As a user can enable debug logging with it, you might want to [remove](https://github.com/dthree/vorpal#commandremove) it for production.

```
Usage: loglevel [options] <level>


set the log level

Options:

  --help  output usage information
```

### Customizing

##### logger.addFormatter(name, level, format)
Creates a `logger[name]` function, which will log the result of `format(msg)` with loglevel `level`. Use this to add custom formatters.

See `customFormatter` [here](https://github.com/AljoschaMeyer/vorpal-log/tree/master/examples) for a working, insightful and useful example.

##### logger.setFilter(filter)
Takes either a custom filter function, a string, or a number.

When logging something, the formatter is passed to the function set by `logger.setFilter`. Logging only happens if this function returns true.

If `logger.setFilter` is passed a function, this function is the new filter function.

If passed a number, the new filter function will only log, if `formatter.level` is greater than or equal to that number.

If passed a string, the new filter function will only log if `formatter.level` is greater than or equal to `formatters[filter].level`.

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