Skip to content

Commit

Permalink
Added transport option
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Aug 17, 2015
1 parent 0daf159 commit a1170e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ Create a new logger. Available options:
- level **{String}**: Provides the logging level. `all` by default.
- types **{Object}**: You can provide the types and priorities.
- print **{Function}**: Provides a function that determines how to print the messages. By default uses `.generateMessage` for generate the mesage that will be outputted.
- transport **{Function}**: Defines what happens with the log message. By default is `console.log`.
- outputType **{Function}**: Provides a function to customize the type in the output.
- outputMessage **{Function}**: Provides a function to customize the message in the output.
- generateMessage **{Function}**: Provides a function that generate the message to be outputted. It combines other internal methods for generate the output (as `.isPrintable` or `.colorize`) and normally you are not interested in the definition of it, but you can provide it as option as well.
Expand Down
5 changes: 3 additions & 2 deletions lib/Acho.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = class Acho
@color = options.color or DEFAULT.COLOR
@level = options.level or DEFAULT.UNMUTED
@types = options.types or DEFAULT.TYPES
@print = options.print or DEFAULT.PRINT
@transport = options.transport or DEFAULT.TRANSPORT
@print = (options.print or DEFAULT.PRINT).bind(this, @transport)
@messages = do =>
messages = {}
for type of @types
Expand Down Expand Up @@ -44,5 +45,5 @@ module.exports = class Acho

generateTypeMessage: (type, message) =>
(message) =>
console.log @generateMessage type, message
@transport @generateMessage type, message
this
5 changes: 3 additions & 2 deletions lib/Default.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

module.exports =

PRINT: ->
PRINT: (transport) ->
for type of @types
console.log @generateMessage type, message for message in @messages[type]
transport @generateMessage type, message for message in @messages[type]

OUTPUT_MESSAGE: (message) -> message
OUTPUT_TYPE: (type) -> "#{type}\t: "
TRANSPORT: console.log

GENERATE_MESSAGE: (type, message) ->
return unless @isPrintable type
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
{
"name": "acho",
"version": "2.0.0",
"description": "An extremely simple (but powerful) logging system for NodeJS and browser.",
"homepage": "https://github.com/Kikobeats/acho",
"version": "2.0.0",
"main": "./index.js",
"author": {
"name": "Kiko Beats",
"email": "[email protected]",
"name": "Kiko Beats",
"url": "https://github.com/Kikobeats"
},
"scripts": {
"test": "sh test/test.sh",
"build": "node ./node_modules/.bin/gulp --require coffee-script"
},
"main": "./index.js",
"repository": "Kikobeats/acho",
"bugs": {
"url": "https://github.com/Kikobeats/acho/issues"
},
"keywords": [
"log",
"logging",
"logger"
"logger",
"logging"
],
"dependencies": {
"chalk": "*",
Expand All @@ -38,9 +35,12 @@
"vinyl-buffer": "*",
"vinyl-source-stream": "*"
},
"license": "MIT",
"engines": {
"node": "*"
},
"homepage": "https://github.com/Kikobeats/acho"
"scripts": {
"build": "node ./node_modules/.bin/gulp --require coffee-script",
"test": "sh test/test.sh"
},
"license": "MIT"
}

0 comments on commit a1170e3

Please sign in to comment.