# penlog

> A simple and powerful logger for nodejs.

Latest version **2.0.0** (published 2018-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install penlog
pnpm add penlog
yarn add penlog
bun add penlog
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-04-03 |
| First published | 2018-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 63.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | blackcater |
| Maintainers | blackcater |

## Links

- npm: https://www.npmjs.com/package/penlog
- Repository: https://github.com/blackcater/penlog
- Issues: https://github.com/blackcater/penlog/issues
- npm.io page: https://npm.io/package/penlog

## Dependencies (4)

- [ora](https://npm.io/package/ora.md) ^2.0.0
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [text-table](https://npm.io/package/text-table.md) ^0.2.0
- [log-symbols](https://npm.io/package/log-symbols.md) ^2.2.0

## Recent versions

- 2.0.0 (latest) — 2018-04-03
- 1.0.0 — 2018-03-08

## README

<p>
    <a href="https://github.com/blackcater"><img alt="logo" width="36" height="36" src="http://oameisqha.bkt.clouddn.com/avatar.png?roundPic/radius/!50p" alt="blackcater">
    </a>
</p>

<p align="center">
    <img alt="logo" src="./penlog.png" width="120" height="120">
</p>

<p align="center">A simple and powerful logger for nodejs.</p>

[![Build Status](https://travis-ci.org/blackcater/penlog.svg?branch=master)](https://travis-ci.org/blackcater/penlog)
[![Coverage Status](https://coveralls.io/repos/github/blackcater/penlog/badge.svg?branch=master)](https://coveralls.io/github/blackcater/penlog?branch=master)

<h2>Install</h2>

```bash
> npm install penlog --save
> yarn install penlog --save
```

<h2>Usage</h2>

```javascript
import { penlog, colors } from 'penlog'

penlog.log(colors.red('hello'), 4).log(colors.blue('world!'), 4)
```

<h2>API</h2>

### Class Penlog

#### Constructor Options

```javascript
options: {
  // where you want to write message, the default value is process.stdout
  stdout: process.stdout
  // where you want to write error message, the default value is process.stderr
  stderr: process.stderr
  // the indent size of per line，the default value is zero
  indent: 0
}
```

#### `static createPenlog([[key, ]options])`

```javascript
import { createPenlog } from 'penlog'

createPenlog() !== createPenlog()
createPenlog({ indent: 2 }) !== createPenlog({ indent: 4 })
createPenlog('pen1') === createPenlog('pen1')
createPenlog('pen1') !== createPenlog('pen2')
```

`createPenlog` will return a instance if `Penlog Class`. If you don't provide the key option, it will return different instance every time.

#### `write([content[, title][, options]])`

```javascript
import { penlog } from 'penlog'

penlog
  .write('hello world!')
  .write('OK!', { indent: 4 })
  .writeln()
  .write('Yes, Sir!')

// -- output --
/*
hello world!    OK!
Yes, Sir!
*/
```

* `contents`: can be a string or array, when it is an array, it will be used by `util.format`.

* `title`: can be a string.
* `options`:
  * `style`: the style for multi-line content. `default` means that before of pre-line content will be empty; `space` means that before of pre-line content will be white space; `title` means that before of pre-line content will be title. The default value is `default`.
  * `error`: whether to use stderr instead stdout. The default value is `false`.
  * `indent`: the length of indentation before this log. The default value is zero.
  * `join`: the string for concat pre-line content. The default value is `\n`.
  * `newline`: whether output `\n` at the end of log, the default value is `false`.
  * `space`: the string between title and content. The default value is white space.

#### `writeln([content[, title][, options]])`

This is same as `write()`, but `options.newline` is `true`.

#### `log([content[, title][, options]])`

```javascript
import { penlog } from 'penlog'

penlog
  .log('line1')
  .log('line2')
  .log('line3', 'title')
  .log('line4\nline5', 'title4-5')
  .log('line6\nline7', 'title6-7', { style: 'default' })

// -- output --
/*
line1
line2
title line3
title4-5 line4
         line5
title6-7 line6
line7

*/
```

```javascript
import { penlog } from 'penlog'

penlog.log('line1\nline2', { join: '|' })

// -- output --
/*
line1|line2

*/
```

```javascript
import { penlog } from 'penlog'

penlog.log('line1\nline2', { indent: 4 })

// -- output --
/*
    line1
    line2

*/
```

#### `info([contents[, title][, options]])`

```javascript
import { penlog } from 'penlog'

penlog
  .info('information1')
  .info('information2-1\ninformation2-2')
  .info('information3', ' I ')
```

![info-1](./docs/info.gif)

#### `warn([contents[, title][, options]])`

```javascript
import { penlog } from 'penlog'

penlog
  .warn('warning1')
  .warn('warning2-1\nwarning2-2')
  .warn('warning3', ' W ')
```

![warn-1](./docs/warn.gif)

#### `error([contents[, title][, options]])`

```javascript
import { penlog } from 'penlog'

penlog
  .error('error1')
  .error('error2-1\nerror2-2')
  .error('error3', ' E ')
```

![error-1](./docs/error.gif)

#### `success([contents[, title][, options]])`

```javascript
import { penlog } from 'penlog'

penlog
  .success('success1')
  .success('success2-1\nsuccess2-2')
  .success('success3', ' S ')
```

![success-1](./docs/success.gif)

#### `indent([number = 2])`

```javascript
import { penlog } from 'penlog'

penlog
  .indent(4)
  .log('line1')
  .indent(4)
  .log('line2')
  .indent(-4)
  .log('line3')

// -- output --
/*
    line1
        line2
    line3

*/
```

Indent output with size number.

#### `table(rows[, options])`

`table` is exported from package [`text-table`](https://github.com/substack/text-table)

#### `loding(text[, options])`

`loading` is exported from package [`ora`](https://github.com/sindresorhus/ora)

### colors

```javascript
import { colors } from 'penlog'
```

`colors` is exported from package [`colors/safe`](https://www.npmjs.com/package/colors)

### symbols

```javascript
import { symbols } from 'penlog'
```

`symbols` is exported from package [`log-symbols`](https://www.npmjs.com/package/log-symbols)

## Contributing

1.  Fork it!
2.  Create your feature branch: `git checkout -b my-new-feature`
3.  Commit your changes: `git commit -am 'Add some feature'`
4.  Push to the branch: `git push origin my-new-feature`
5.  Submit a pull request :D

## Author

**penlog** © [blackcater](https://github.com/blackcater), Released under the [MIT](./LICENSE) License.<br>
Authored and maintained by blackcater with help from contributors ([list](https://github.com/blackcater/penlog/contributors)).

> [http://www.blackcater.win](http://www.blackcater.win) · GitHub [@blackcater](https://github.com/blackcater)

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