lwhiteley / AngularLogExtender

AngularLogExtender is an AngularJS module that extends the Angular $log functionality. It uses the native $decorator to push the $log pass its capabilities and provide new functionality such as configuring the $log for different environments such as production and development
MIT License
40 stars 8 forks source link

color support for more than one argument #37

Closed rweng closed 9 years ago

rweng commented 9 years ago

Hi,

color support works fine when using

$log.warn("test") // printed correctly in orange

however, with multiple parameters it doesn't work:

$log.warn("test", "test") // printed incorrectly in black

All the best, Robin

ferronrsmith commented 9 years ago

Second field is usually reserved for color overrides. The problem you're having is the color function is trying to detect the second param as a valid color property, but since it isn't, its' rejected. The workaround would be to fallback to a string input if validation fails.

 $log.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
rweng commented 9 years ago

arg. I thought since you have examples like $log = $log.getInstance(...), that the API would actually stay the same as in normal angular $log, which you do use like $log.log(p1, p2, p3, ...).

Too bad, this is actually a show-stopper for us, since we are not going to use a custom API. I would expect the styling to be overwritten as it is used on the provider, with $log.setLogMethodColor.

ferronrsmith commented 9 years ago

I get what your saying, but it's not really a limitation of the library per say, but the browsers. If you take a look at the documentation for coloring in chrome/ff the second parameter always defines color

console.log("%cThis will be formatted with large, blue text", "color: blue; font-size: x-large");

https://developer.chrome.com/devtools/docs/console#styling-console-output-with-css.

If if you use $log.warn or console.log, you still would need to do the same thing. We can iterate over the items in the argument list apply the coloring function and grouping the respective params, but they must be strings..