### Log Wrapper

Okay, let's move on to the actual log function which prints things in the console. Not only should it output the given messages in the user's console, but it should also update the history in order to keep track of what's being logged (which might or might not be useful).

That sounds difficult. Well worry not, it's going to be as smooth as butter. We already know this mixin should accept only two parameters: the logging level, and the message.

Now, we need to deal with updating the history. This is actually a little tougher, but once you get used to map manipulation, it becomes clearer.

Before looking at the code, let me explain how is the history working. Basically, it's a map where keys are the logging levels, and values are lists of logged messages. For instance, you could have something like:

Okay. Let's go.

It involves quite a few unfriendly lines, but when you explain each line individually, it all makes sense eventually.

We're done here, but we spoke about adding shorthand functions. Let's do that now before we forget:

That's it. One last thing we could do, but isn't really mandatory, is testing whether logger has been included before trying to use the global map. Not only do we prevent stupid mistakes, but we could also make the logger instantiation optional by doing it on the fly.

We'll start with the first (and least useful) of both extra mixins, the helper. It's really a gadget at this point since all it does is print a CSS rule with logging levels as selectors, and explanations as values.

This is intented to give some help to developers when they don't really know which logging level they should use. It could have been written as a comment but I wanted to try this help printer thingie.

You use it like this:

...and it compiles as:

Nothing special. The other extra mixin is way more interesting. It uses the history to print all logs that have been registered during the compilation.

Again, simple use:

... which would output (based on our earlier example):

## Final Thoughts

As you can see, the code is quite light in the end, plus most of its bulk is comments. I think it provides a nice clean API helping keeping track of what's being logged in any given project.

This is tool aimed at library and framework developers. If you happen to be one, please give this a try if you think it could be useful, and give me your feedback.

Feel free to grab the mixin from GitHub, or play with it directly on SassMeister.