Skip to content

Commit

Permalink
Add symbol special keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jan 25, 2016
1 parent 134fa13 commit c287277
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/Constants.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module.exports =
MIN_DIFF_MS: 10000
MUTED: 'silent'
UNMUTED: 'all'
SYMBOL_KEYWORD: 'symbol'
ENV: do -> process?.env.NODE_ENV?.toLowerCase() or undefined
27 changes: 22 additions & 5 deletions lib/Default.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict'

chalk = require 'chalk'
humanizeMs = require 'ms'
chalk = require 'chalk'
figures = require 'figures'
CONST = require './Constants'
formatUtil = require 'format-util'

module.exports =
print: ->
for type of @types
Expand All @@ -12,6 +14,8 @@ module.exports =
outputMessage: (message) -> message
outputType: (type) ->
align = if @align then "\t" else " "
if @keyword
type = if @keyword is CONST.SYMBOL_KEYWORD then @types[type].symbol else type
"#{type}#{align}"

transport: console.log
Expand All @@ -22,8 +26,6 @@ module.exports =
colorType = @types[type].color
message = @outputMessage message
message = @colorize @types.line.color, message

keyword = if @keyword? then @keyword else type
diff = null

if @diff
Expand All @@ -35,7 +37,7 @@ module.exports =
@diff[type] = new Date()
diff = " +0ms"

messageType = @outputType keyword
messageType = @outputType type
messageType = @colorize colorType, messageType

output = messageType + message
Expand Down Expand Up @@ -71,25 +73,40 @@ module.exports =

types:
line:
color: 'gray'
color : 'gray'
symbol: ''

error:
level : 0
color : 'red'
symbol: figures.cross

warn:
level : 1
color : 'yellow'
symbol: figures.warning

success:
level : 2
color : 'green'
symbol: figures.tick

info:
level : 3
color : 'white'
symbol: figures.info

verbose:
level : 4
color : 'cyan'
symbol: figures.info

debug:
level : 5
color : 'blue'
symbol: figures.info

silly:
level : 6
color : 'magenta'
symbol: figures.info
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"chalk": "~1.1.1",
"coffee-script": "~1.10.0",
"existential-assign": "~1.2.2",
"figures": "~1.4.0",
"format-util": "1.0.3",
"ms": "~0.7.1"
},
Expand Down
4 changes: 4 additions & 0 deletions test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ describe 'Acho ::', ->
it 'specifying a keyword', ->
printLogs Acho level: 'silly', color: true, keyword: 'acho'

it 'specifying a special "symbol" keyword', ->
printLogs Acho level: 'silly', color: true, keyword: 'symbol'

it 'enabling diff between logs', (done) ->
acho = Acho
level: 'silly'
color: true
diff: true
align: false

printWarn = -> acho.warn 'hello world'
printErr = -> acho.error 'oh noes!'
Expand Down

0 comments on commit c287277

Please sign in to comment.