update
This commit is contained in:
+29
@@ -2,6 +2,35 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
### [2.15.3](https://github.com/nuxt/consola/compare/v2.15.2...v2.15.3) (2021-02-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add `.raw` to mocked functions ([987dadc](https://github.com/nuxt/consola/commit/987dadcc81a82698051ade2384ae2f0fc12d8aef))
|
||||
|
||||
### [2.15.2](https://github.com/nuxt/consola/compare/v2.15.1...v2.15.2) (2021-02-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add isRaw flag only for wrapped calls ([23b1184](https://github.com/nuxt/consola/commit/23b1184e2897f5d33943bec7180fb2427402d400)), closes [nuxt/nuxt.js#8752](https://github.com/nuxt/nuxt.js/issues/8752)
|
||||
|
||||
### [2.15.1](https://github.com/nuxt/consola/compare/v2.15.0...v2.15.1) (2021-02-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* skip logObj check for wrapped calls (fixes [#109](https://github.com/nuxt/consola/issues/109)) ([091a244](https://github.com/nuxt/consola/commit/091a24423bb9c28b7371e7af849b15c7e39747fa))
|
||||
|
||||
## [2.15.0](https://github.com/nuxt/consola/compare/v2.14.0...v2.15.0) (2020-08-05)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **types:** use union type for `ConsolaLogObject.type` ([#100](https://github.com/nuxt/consola/issues/100)) ([a6eba53](https://github.com/nuxt/consola/commit/a6eba532381bcec9c84ac5600ac668aca87c8487))
|
||||
* support `formatOptions.date` to optionally hide date ([#101](https://github.com/nuxt/consola/issues/101)) ([6bf733f](https://github.com/nuxt/consola/commit/6bf733f2b9a5320584bdd0de7de08f4341c74335))
|
||||
|
||||
## [2.14.0](https://github.com/nuxt/consola/compare/v2.13.0...v2.14.0) (2020-06-26)
|
||||
|
||||
|
||||
|
||||
+16
-15
@@ -1,7 +1,8 @@
|
||||
<p align="center">
|
||||
<h1>🐨 Consola</h1>
|
||||
<span>Elegant Console Logger for Node.js and Browser</span>
|
||||
</p>
|
||||

|
||||
|
||||
# Consola
|
||||
|
||||
> Elegant Console Logger for Node.js and Browser
|
||||
|
||||
[![Standard JS][standard-js-src]][standard-js-href]
|
||||
[![npm version][npm-version-src]][npm-version-href]
|
||||
@@ -11,16 +12,16 @@
|
||||
|
||||
## Why Consola?
|
||||
|
||||
- Easy to use
|
||||
- Fancy output with fallback for minimal environments
|
||||
- Pluggable reporters
|
||||
- Consistent command line interface (CLI) experience
|
||||
- Tag support
|
||||
- Redirect `console` and `stdout/stderr` to the consola and easily restore redirect.
|
||||
- Browser support
|
||||
- Pause/Resume support
|
||||
- Mocking support
|
||||
- Spam prevention by throttling logs
|
||||
👌 Easy to use<br>
|
||||
💅 Fancy output with fallback for minimal environments<br>
|
||||
🔌 Pluggable reporters<br>
|
||||
💻 Consistent command line interface (CLI) experience<br>
|
||||
🏷 Tag support<br>
|
||||
🚏 Redirect `console` and `stdout/stderr` to consola and easily restore redirect.<br>
|
||||
🌐 Browser support<br>
|
||||
⏯ Pause/Resume support<br>
|
||||
👻 Mocking support<br>
|
||||
👮♂️ Spam prevention by throttling logs<br>
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -165,7 +166,7 @@ An array of active reporters.
|
||||
The level to display logs. Any logs at or above this level will be displayed.
|
||||
List of available levels [here](./src/types.js).
|
||||
|
||||
You can set log level using `CONSOLA_LEVEL` environment variable.
|
||||
You can set the log level using the `CONSOLA_LEVEL` environment variable, which must have the numeric log level as its value.
|
||||
|
||||
## `logObject`
|
||||
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+12
-13
@@ -1,25 +1,25 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"consola@2.14.0",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"consola@2.15.3",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "consola@2.14.0",
|
||||
"_id": "consola@2.14.0",
|
||||
"_from": "consola@2.15.3",
|
||||
"_id": "consola@2.15.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-A2j1x4u8d6SIVikhZROfpFJxQZie+cZOfQMyI/tu2+hWXe8iAv7R6FW6s6x04/7zBCst94lPddztot/d6GJiuQ==",
|
||||
"_integrity": "sha512-9vAdYbHj6x2fLKC4+oPH0kFzY/orMZyG2Aj+kNylHxKGJ/Ed4dpNyAQYwJOdqO4zdM7XpVHmyejQDcQHrnuXbw==",
|
||||
"_location": "/consola",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "consola@2.14.0",
|
||||
"raw": "consola@2.15.3",
|
||||
"name": "consola",
|
||||
"escapedName": "consola",
|
||||
"rawSpec": "2.14.0",
|
||||
"rawSpec": "2.15.3",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.14.0"
|
||||
"fetchSpec": "2.15.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@nuxt/builder",
|
||||
@@ -38,12 +38,11 @@
|
||||
"/@nuxt/webpack",
|
||||
"/@nuxtjs/axios",
|
||||
"/@nuxtjs/eslint-module",
|
||||
"/@nuxtjs/proxy",
|
||||
"/webpackbar"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/consola/-/consola-2.14.0.tgz",
|
||||
"_spec": "2.14.0",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/consola/-/consola-2.15.3.tgz",
|
||||
"_spec": "2.15.3",
|
||||
"_where": "/home/node/nuxt",
|
||||
"browser": "dist/consola.browser.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/nuxt/consola/issues"
|
||||
@@ -132,5 +131,5 @@
|
||||
"test:types": "tsc -p test/types"
|
||||
},
|
||||
"typings": "types/consola.d.ts",
|
||||
"version": "2.14.0"
|
||||
"version": "2.15.3"
|
||||
}
|
||||
|
||||
+16
-15
@@ -19,11 +19,13 @@ class Consola {
|
||||
|
||||
// Create logger functions for current instance
|
||||
for (const type in this._types) {
|
||||
this[type] = this._wrapLogFn(Object.assign(
|
||||
{ type },
|
||||
this._types[type],
|
||||
this._defaults
|
||||
))
|
||||
const defaults = {
|
||||
type,
|
||||
...this._types[type],
|
||||
...this._defaults
|
||||
}
|
||||
this[type] = this._wrapLogFn(defaults)
|
||||
this[type].raw = this._wrapLogFn(defaults, true)
|
||||
}
|
||||
|
||||
// Use _mockFn if is set
|
||||
@@ -112,7 +114,7 @@ class Consola {
|
||||
console['__' + type] = console[type] // eslint-disable-line no-console
|
||||
}
|
||||
// Override
|
||||
console[type] = this[type] // eslint-disable-line no-console
|
||||
console[type] = this[type].raw // eslint-disable-line no-console
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +145,7 @@ class Consola {
|
||||
|
||||
// Override
|
||||
stream.write = (data) => {
|
||||
this[type](String(data).trim())
|
||||
this[type].raw(String(data).trim())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,22 +188,21 @@ class Consola {
|
||||
|
||||
for (const type in this._types) {
|
||||
this[type] = this._mockFn(type, this._types[type]) || this[type]
|
||||
this[type].raw = this[type]
|
||||
}
|
||||
}
|
||||
|
||||
_wrapLogFn (defaults) {
|
||||
function logFn () {
|
||||
_wrapLogFn (defaults, isRaw) {
|
||||
return (...args) => {
|
||||
if (paused) {
|
||||
queue.push([this, defaults, arguments])
|
||||
queue.push([this, defaults, args, isRaw])
|
||||
return
|
||||
}
|
||||
|
||||
return this._logFn(defaults, arguments)
|
||||
return this._logFn(defaults, args, isRaw)
|
||||
}
|
||||
return logFn.bind(this)
|
||||
}
|
||||
|
||||
_logFn (defaults, args) {
|
||||
_logFn (defaults, args, isRaw) {
|
||||
if (defaults.level > this.level) {
|
||||
return this._async ? Promise.resolve(false) : false
|
||||
}
|
||||
@@ -213,7 +214,7 @@ class Consola {
|
||||
}, defaults)
|
||||
|
||||
// Consume arguments
|
||||
if (args.length === 1 && isLogObj(args[0])) {
|
||||
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
||||
Object.assign(logObj, args[0])
|
||||
} else {
|
||||
logObj.args = Array.from(args)
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ import { formatDate } from '../utils/date'
|
||||
const DEFAULTS = {
|
||||
dateFormat: 'HH:mm:ss',
|
||||
formatOptions: {
|
||||
date: true,
|
||||
colors: false,
|
||||
compact: true
|
||||
}
|
||||
@@ -40,7 +41,7 @@ export default class BasicReporter {
|
||||
}
|
||||
|
||||
formatDate (date) {
|
||||
return formatDate(this.options.dateFormat, date)
|
||||
return this.options.formatOptions.date ? formatDate(this.options.dateFormat, date) : ''
|
||||
}
|
||||
|
||||
filterAndJoin (arr) {
|
||||
|
||||
+4
-2
@@ -9,6 +9,7 @@ import { TYPE_COLOR_MAP, LEVEL_COLOR_MAP } from '../utils/fancy'
|
||||
const DEFAULTS = {
|
||||
secondaryColor: 'grey',
|
||||
formatOptions: {
|
||||
date: true,
|
||||
colors: true,
|
||||
compact: false
|
||||
}
|
||||
@@ -59,7 +60,8 @@ export default class FancyReporter extends BasicReporter {
|
||||
|
||||
const secondaryColor = chalkColor(this.options.secondaryColor)
|
||||
|
||||
const date = secondaryColor(this.formatDate(logObj.date))
|
||||
const date = this.formatDate(logObj.date)
|
||||
const coloredDate = date && secondaryColor(date)
|
||||
|
||||
const type = this.formatType(logObj, isBadge)
|
||||
|
||||
@@ -69,7 +71,7 @@ export default class FancyReporter extends BasicReporter {
|
||||
|
||||
let line
|
||||
const left = this.filterAndJoin([type, formattedMessage])
|
||||
const right = this.filterAndJoin([tag, date])
|
||||
const right = this.filterAndJoin([tag, coloredDate])
|
||||
const space = width - stringWidth(left) - stringWidth(right) - 2
|
||||
|
||||
if (space > 0 && width >= 80) {
|
||||
|
||||
+18
-4
@@ -13,10 +13,24 @@ export enum LogLevel {
|
||||
Verbose= Infinity,
|
||||
}
|
||||
|
||||
export type logType =
|
||||
| 'silent'
|
||||
| 'fatal'
|
||||
| 'error'
|
||||
| 'warn'
|
||||
| 'log'
|
||||
| 'info'
|
||||
| 'success'
|
||||
| 'debug'
|
||||
| 'trace'
|
||||
| 'verbose'
|
||||
| 'ready'
|
||||
| 'start'
|
||||
|
||||
export interface ConsolaLogObject {
|
||||
level?: LogLevel,
|
||||
tag?: string,
|
||||
type?: string,
|
||||
type?: logType,
|
||||
message?: string,
|
||||
additional?: string | string[],
|
||||
args?: any[],
|
||||
@@ -25,7 +39,7 @@ export interface ConsolaLogObject {
|
||||
|
||||
export interface ConsolaReporterLogObject {
|
||||
level: LogLevel,
|
||||
type: string,
|
||||
type: logType,
|
||||
tag: string;
|
||||
args: any[],
|
||||
date: Date,
|
||||
@@ -33,7 +47,7 @@ export interface ConsolaReporterLogObject {
|
||||
|
||||
type ConsolaMock = (...args: any) => void
|
||||
|
||||
type ConsolaMockFn = (type: string, defaults: ConsolaLogObject) => ConsolaMock
|
||||
type ConsolaMockFn = (type: logType, defaults: ConsolaLogObject) => ConsolaMock
|
||||
|
||||
export interface ConsolaReporterArgs {
|
||||
async: boolean,
|
||||
@@ -47,7 +61,7 @@ export interface ConsolaReporter {
|
||||
|
||||
export interface ConsolaOptions {
|
||||
reporters?: ConsolaReporter[],
|
||||
types?: { [type: string]: ConsolaLogObject },
|
||||
types?: { [type in logType]: ConsolaLogObject },
|
||||
level?: LogLevel,
|
||||
defaults?: ConsolaLogObject,
|
||||
async?: boolean,
|
||||
|
||||
Reference in New Issue
Block a user