Coder Social home page Coder Social logo

logan's Introduction

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

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

Configuration

If you want to suppress all output, during tests for example, just set silent to true.

logan.set({'foo': ['foo', 'red']});
logan.silent = true;
logan.foo(); // No output
logan.silent = false;
logan.foo(): // 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.

logan's People

Contributors

typicode avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.