Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Commit

Permalink
Loggers should accept a varying list of parameters as tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
johanbrook committed Feb 25, 2015
1 parent 6283613 commit 6b397aa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
19 changes: 17 additions & 2 deletions loggers/local.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// Local log

function toString(arr) {
return '[' + _.invoke(arr, 'toUpperCase').join(' ') + ']';
}

Loggers.local = function(level, message, tags) {
var method = (function() {
switch (level) {
Expand All @@ -16,8 +21,18 @@ Loggers.local = function(level, message, tags) {
[EMAILS SOMETHING-ELSE] This is my message.
*/
tags = _.invoke(tags, 'toUpperCase').join(' ');
console[method]('[' + tags + ']', message);

var tagsArgs = _.rest(arguments, 2);

if(!Array.isArray(tags) && tagsArgs.length) {
tags = tagsArgs;
}

if(Array.isArray(tags)) {
tags = toString(tags);
}

console[method](tags, message);
} else {
console[method](message);
}
Expand Down
11 changes: 9 additions & 2 deletions loggers/loggly.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ Loggers.loggly = function(logglyClient, baseParams) {
// @param {string} message
// @param {(string|array)} [tags]
return function log(level, message, tags) {
if (tags && _.isString(tags))
tags = [tags];
if(tags) {
var tagsArgs = _.rest(arguments, 2);

if(_.isString(tags)) {
tags = [tags];
} else if(tagsArgs.length){
tags = tagsArgs;
}
}

var toLog = {
message: message,
Expand Down
4 changes: 4 additions & 0 deletions tests/logger-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ describe 'Logger', ->
Logger[method]('Foo', ['bar', 'baz'])
spies[method].should.have.been.calledWith '[BAR BAZ]', 'Foo'

it 'should be able to take a dynamic list of tags', ->
Logger.info 'Foo', 'tag1', 'tag2', 'tag3'
spies.info.should.have.been.calledWith '[TAG1 TAG2 TAG3]', 'Foo'

describe 'logger', ->

it 'should exist as a function', ->
Expand Down

0 comments on commit 6b397aa

Please sign in to comment.