Logan
Logan is a mini template system for the console and colors.
It allows to cleanly separate content from style and create beautiful logging functions.
Example
Let's say you want to write a logging function that says hello.
// Without Logan { console;} // With Loganvar hello = logan ;
Usage
var logan = ;
set
This is the most useful method of logan. It lets you define all your templates in one place.
logan; logan;
Notice how easy it is to see what all your logging functions will output.
Also, with set
your module users can easily theme logs:
// Overriding omg to be... more OMG!!!logan;
create
Returns a logging function.
var info = logan;;
compile
Returns a function which returns a string when called.
var info = logan;console;
Syntax
- % is used for string replacement.
- {} lets you define blocks.
- . means default style.
- styles can be chained (example: bold.underline.red).
{} usage:
// for example, instead of writing this:var green = logan; // using {} you can writevar green = logan;
Configuration
If you want to suppress all output, during tests for example, just set silent
to true
.
logan;logansilent = true;logan; // No outputlogansilent = false;logan: // will output 'foo'
About the name
Since there's a templating engine called hogan and this one is about logging, it was called logan.
More
If you want to see how Logan can be used in another project, you can have a look at ShoutJS.