penlog

2.0.0 • Public • Published

logo

logo

A simple and powerful logger for nodejs.

Build Status Coverage Status

Install

> npm install penlog --save
> yarn install penlog --save

Usage

import { penlog, colors } from 'penlog'

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

API

Class Penlog

Constructor Options

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])

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]])

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]])

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

*/
import { penlog } from 'penlog'

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

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

*/
import { penlog } from 'penlog'

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

// -- output --
/*
    line1
    line2

*/

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

import { penlog } from 'penlog'

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

info-1

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

import { penlog } from 'penlog'

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

warn-1

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

import { penlog } from 'penlog'

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

error-1

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

import { penlog } from 'penlog'

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

success-1

indent([number = 2])

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

loding(text[, options])

loading is exported from package ora

colors

import { colors } from 'penlog'

colors is exported from package colors/safe

symbols

import { symbols } from 'penlog'

symbols is exported from 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, Released under the MIT License.
Authored and maintained by blackcater with help from contributors (list).

http://www.blackcater.win · GitHub @blackcater

Readme

Keywords

none

Package Sidebar

Install

npm i penlog

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

64.8 kB

Total Files

9

Last publish

Collaborators

  • blackcater