logan
Mini template system for the console and colors
Last updated 12 years ago by typicode .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install logan 
SYNC missed versions from official npm registry.

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
function hello(arg) {
  console.log('Hello'.bold.green + ' : ' + arg.cyan);
}

// With Logan
var hello = logan.create('Hello : %', 'bold.green . cyan')

hello('world');

Usage

var logan = require('logan');

set

This is the most useful method of logan. It lets you define all your templates in one place.

logan.set({
  info: ['info : %', 'yellow'],
  warn: ['warn : %', 'orange'],
  omg : ['omg  : %', 'rainbow']
});

logan.info('some info');

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.set({
  omg: ['OMG : % !!!', 'red . . red']
});

create

Returns a logging function.

var info = logan.create('info : %', 'yellow');
info('some text');

compile

Returns a function which returns a string when called.

var info = logan.compile('info : %', 'yellow');
console.log(info('some text'));

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 foo = logan.create('some long green string', 'green green green green');

// using {} you can write
var foo = logan.create('{some long green string}', 'green');

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.

Current Tags

  • 0.0.2                                ...           latest (12 years ago)

2 Versions

  • 0.0.2                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |