diff --git a/README.md b/README.md index c748aa2..9e2d202 100755 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/Acho.coffee b/lib/Acho.coffee index 6585b01..09df540 100644 --- a/lib/Acho.coffee +++ b/lib/Acho.coffee @@ -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 @@ -44,5 +45,5 @@ module.exports = class Acho generateTypeMessage: (type, message) => (message) => - console.log @generateMessage type, message + @transport @generateMessage type, message this diff --git a/lib/Default.coffee b/lib/Default.coffee index e5552db..f5f2422 100644 --- a/lib/Default.coffee +++ b/lib/Default.coffee @@ -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 diff --git a/package.json b/package.json index 3b44924..92cec13 100755 --- a/package.json +++ b/package.json @@ -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": "josefrancisco.verdu@gmail.com", + "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": "*", @@ -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" }