Skip to content

Commit

Permalink
Configurable timestamp timing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 29, 2016
1 parent a619744 commit 4fc59d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ Default: `false`.

Enable or disable print log level in upper case.

##### **{Boolean}** timestamp
##### **{Number}** timestamp

Default: `false`.
Default: `0`.

Prints a counter timestamp associated with each log line. Useful for debug log traces.

Expand Down
2 changes: 1 addition & 1 deletion examples/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var Acho = require('..')
var acho = Acho({
diff: true,
timestamp: true,
timestamp: 1000,
upperCase: true,
context: 'generated'
// keyword: 'symbol'
Expand Down
22 changes: 14 additions & 8 deletions lib/Default.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

humanizeMs = require 'ms'
ms = require 'ms'
chalk = require 'chalk'
formatUtil = require './Format'
CONST = require './Constants'
Expand Down Expand Up @@ -33,11 +33,17 @@ module.exports =

outputCounter: ->
return '' unless @timestamp
now = Date.now()
diff = now - @timestamp
++@counter if (diff >= 1000)
@timestamp = Date.now()
" [#{@decorateCounter(@counter)}]"

@_counterTimestamp ||= 0
@_lastTimestamp ||= null

diff = Date.now() - @_lastTimestamp

if diff >= @timestamp
++@_counterTimestamp
@_lastTimestamp = Date.now()

" [#{@decorateCounter(@_counterTimestamp)}]"

outputSeparator: (type) ->
return '' if @keyword
Expand All @@ -57,7 +63,7 @@ module.exports =

if @diff
if @diff[type]
diff = humanizeMs(Date.now() - @diff[type])
diff = ms(Date.now() - @diff[type])
diff = " +#{diff}"
@diff[type] = Date.now()
else
Expand Down Expand Up @@ -123,7 +129,7 @@ module.exports =

align: " "
color: true
counter: 0
timestamp: 0

level: CONST.UNMUTED

Expand Down

0 comments on commit 4fc59d3

Please sign in to comment.