angularjs-logDecorator
angularjs-logDecorator copied to clipboard
$log.info with objects
Hey,
first of all: Great Decorator - Example, thanks!
I often use $log.info with objects and often with multiple params, to show all properties, but with your decorator these are all gone... and don't get "logged".
Here is my updated function to support both features:
var enhancedLogFn = function ( )
{
// prepend a timestamp and optional classname to the original output message
var now = DateTime.formattedNow(),
args = [now, className || ''], extraArguments = [],
argCount = arguments.length,
format = ["{0} - {1}"], formatCounter = 2, i;
if(argCount >= 1){
for(i in arguments){
if(typeof(arguments[i]) in { "array":1, "object":1, "error": 1, "function":1 } ){
extraArguments.push(arguments[i]);
}else{
format.push(" {",formatCounter++,"};");
args.push(arguments[i]);
}
}
}
args = [ supplant(format.join(""), args) ];
args = colorify( supplant.apply( null, args ), colorCSS );
args = args.concat(extraArguments);
logFn.apply( null, args );
};
Now you can use:
$log.info("My Info", someObject, [myArray:2], "other Text");