Skip to content

Commit

Permalink
feat: support formatOptions.date to optionally hide date (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
develohpanda authored Aug 4, 2020
1 parent 2d2115f commit 6bf733f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/reporters/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { formatDate } from '../utils/date'
const DEFAULTS = {
dateFormat: 'HH:mm:ss',
formatOptions: {
date: true,
colors: false,
compact: true
}
Expand Down Expand Up @@ -39,8 +40,8 @@ export default class BasicReporter {
}
}

formatDate (date) {
return formatDate(this.options.dateFormat, date)
formatDate(date) {
return this.options.formatOptions.date ? formatDate(this.options.dateFormat, date) : ''
}

filterAndJoin (arr) {
Expand Down
6 changes: 4 additions & 2 deletions src/reporters/fancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)

Expand All @@ -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) {
Expand Down

0 comments on commit 6bf733f

Please sign in to comment.