forked from daren.hsu/line_push
update
This commit is contained in:
+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) {
|
||||
|
||||
Reference in New Issue
Block a user