log-horizon
Advanced tools
Comparing version 0.0.0 to 0.1.0
const logUpdate = require('log-update') | ||
const emoji = require('./emoji') | ||
const getIcons = require('./icons') | ||
@@ -13,12 +13,10 @@ module.exports = class Logger { | ||
setOptions(options = {}) { | ||
this.options = options | ||
setOptions(options) { | ||
this.options = Object.assign({ | ||
logLevel: 3, | ||
logUpdate: true, | ||
statusType: 'emoji' | ||
}, this.options, options) | ||
if (this.options.logLevel === undefined) { | ||
this.options.logLevel = 3 | ||
} | ||
if (this.options.logUpdate === undefined) { | ||
this.options.logUpdate = true | ||
} | ||
this.icons = getIcons(this.options.statusType) | ||
} | ||
@@ -71,3 +69,3 @@ | ||
this.status(emoji.warning, message) | ||
this.status(this.icons.warning, message) | ||
} | ||
@@ -82,7 +80,7 @@ | ||
if (typeof err === 'string') { | ||
return this.status(emoji.error, err) | ||
return this.status(this.icons.error, err) | ||
} | ||
if (err instanceof Error) { | ||
this.status(emoji.error, err.stack) | ||
this.status(this.icons.error, err.stack) | ||
} | ||
@@ -92,7 +90,7 @@ } | ||
progress(message) { | ||
this.status(emoji.progress, message, true) | ||
this.status(this.icons.progress, message, true) | ||
} | ||
success(message) { | ||
this.status(emoji.success, message) | ||
this.status(this.icons.success, message) | ||
} | ||
@@ -102,4 +100,4 @@ | ||
// Unless `update` is set | ||
// Mainly used in `progress-plugin.js` | ||
status(emoji, message, update = false) { | ||
// Mainly used in `.progress` | ||
status(icon, message, update = false) { | ||
if (this.options.logLevel < 3) { | ||
@@ -109,3 +107,3 @@ return | ||
const status = emoji + ' ' | ||
const status = icon + ' ' | ||
@@ -112,0 +110,0 @@ if (update && this.options.logUpdate) { |
{ | ||
"name": "log-horizon", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "A fancy logger for CLI apps.", | ||
@@ -23,7 +23,8 @@ "repository": { | ||
"dependencies": { | ||
"chalk": "^2.3.1", | ||
"log-update": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"bili": "^3.0.2", | ||
"eslint-config-rem": "^3.0.0", | ||
"prompts": "^0.1.1", | ||
"xo": "^0.18.0" | ||
@@ -30,0 +31,0 @@ }, |
# log-horizon | ||
[![NPM version](https://img.shields.io/npm/v/log-horizon.svg?style=flat)](https://npmjs.com/package/log-horizon) [![NPM downloads](https://img.shields.io/npm/dm/log-horizon.svg?style=flat)](https://npmjs.com/package/log-horizon) [![CircleCI](https://circleci.com/gh/egoist/log-horizon/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/log-horizon/tree/master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate) [![chat](https://img.shields.io/badge/chat-on%20discord-7289DA.svg?style=flat)](https://chat.egoist.moe) | ||
[![NPM version](https://img.shields.io/npm/v/log-horizon.svg?style=flat)](https://npmjs.com/package/log-horizon) [![NPM downloads](https://img.shields.io/npm/dm/log-horizon.svg?style=flat)](https://npmjs.com/package/log-horizon) [![CircleCI](https://circleci.com/gh/egoist/log-horizon/tree/master.svg?style=shield&circle-token=d372afd8d560fb9522f85d967ba19e998a8ee321)](https://circleci.com/gh/egoist/log-horizon/tree/master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate) [![chat](https://img.shields.io/badge/chat-on%20discord-7289DA.svg?style=flat)](https://chat.egoist.moe) | ||
@@ -20,5 +20,5 @@ ## Install | ||
Check out the [example code](./example.js), preview: | ||
Check out the [example code](./examples/_log.js), preview: | ||
<img src="https://i.loli.net/2018/02/28/5a958d3cc7779.gif" width="300" alt="preview"> | ||
<img src="https://cdn.rawgit.com/egoist/93995ac552ac66d38631ed4bff1d7cc1/raw/cf167f27e4033aff5be32115c4c313ebca885703/preview-log-horizon.svg" width="600" alt="preview"> | ||
@@ -48,4 +48,12 @@ ## API | ||
#### options.statusType | ||
Type: `string`<br> | ||
Default: `'emoji'`<br> | ||
Possible values: `'emoji'` `'badge'` `'text'` | ||
### Methods | ||
#### logger.setOptions(options) | ||
#### logger.success(message) | ||
@@ -57,2 +65,4 @@ | ||
#### logger.debug(message) | ||
#### logger.progress(message) | ||
@@ -59,0 +69,0 @@ |
7419
8
126
86
2
+ Addedchalk@^2.3.1
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)