wireapp/acho

Name: acho

Owner: Wire Swiss GmbH

Description: An extremely simple (but powerful) logging system for NodeJS & Browser.

Forked from: achojs/acho

Created: 2016-09-30 10:35:41.0

Updated: 2017-10-07 16:32:19.0

Pushed: 2016-09-30 12:50:26.0

Homepage:

Size: 395

Language: CoffeeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

acho


acho

Last version Build Status Coverage Status Dependency status Dev Dependencies Status NPM Status Donate

An extremely simple (but powerful) logging system for NodeJS and browser.

Why

Install
install acho

If you want to use it in the browser (powered by Browserify):

r install acho --save

and later add it to your HTML:

ipt src="bower_components/acho/dist/acho.js"></script>
Usage
First steps

Acho exports itself according to UMD best practices, which means that no matter where you are using the library, you get a version tailored for your environment.

If you're using a module loader (or Node), simple require the library as you would any other module.

If you're using a browser, the library falls back to attaching itself to window as the global Acho.

CommonJS
Acho = require('acho');
acho = Acho();
Global/Browser
acho = Acho();
AMD

I don't use personally use AMD, so I can't conjure an example, but it should work fine as well.

It's time to use it!


acho

.info('hello world');

All public methods are chainable:


acho


o('hello world')
or('something bad happens');

Maybe you don't want to output the message, but store it for later use:


acho

.push('success', 'good job', 'well done', 'great!');
ole.log(acho.messages.success);

If you want to print previously stored messages, just call the method print:


acho

.print()

You might be thinking: Can I combine both, to store and both print a message? Absolutely!


acho

.add('info', 'this message is printed and stored');
ole.log(acho.messages.info)
Defining the level

Establishing the loglevel is a good way to filter out undesired information from output. The available levels by default are:

Additionally exists two special levels:

The default log level is all. You can define it in the constructor:

acho = Acho({level: 'debug'})

or at runtime:

.level = 'debug';
Customization

You can completely customize the library to your requirements: changes colors, add more types, sort the priorities… the internal structure of the object is public and you can edit it dynamically. You have the power.

By default the messages structure is brief: Just the message type followed by the message itself.

But you can easily modify the output. For example, let's add a timestamp to each message:


acho

acho = Acho({
lor: true,
vel: 'debug',

 Customize how to print the 'type' of each message
tputType: function(type) {
return '[' + type + '] » ';


 Customize how to print the message.
 Add things before and/or after.
tputMessage: function(message) {
return Date() + ' :: ' + message;



.info('I am hungry');

If you need customize more the output you can setup .print .generateMessage (see below) that are a more low level methods for generate and print the output message.

API
Acho({Object} [options])

Create a logger. Available options:

{String} keyword

Default: loglevel

Instead of print the type log level, print the keyword. By default this behavior is not activated.

You can pass the special keyword symbol to show an unicode icon. This is special behavior for CLI programs.

{String} align

Default:

It adds an alignment separator between the type of the message and the message.

You can provide your own separator or disable it providing a false.

{Boolean} diff

Default: false

Prints timestamp between log from the same level. Specially useful to debug timmings.

{Boolean} color

Default: false.

Enable or disable colorized output.

{Boolean} upperCase

Default: false.

Enable or disable print log level in upper case.

{Number} timestamp

Default: 0.

Prints a counter timestamp associated with each log line. Useful for debug log traces.

{String} level

Default: all

Provides the logging level. This sets from what level print logs using tranport.

Additionally you can provide muted to express don't print logs.

{Function} transport

Default: console.log

Defines where write the log message.

{Object} types

You can provide the types and priorities.

{Object} messages

It provides a initial internal store state per each log level. This option is useful when you want to integrate the logger with the ouptut of a delayed function.

{Function} print

Provides a function that determines how to print the messages. By default uses .generateMessage for generate the mesage that will be outputted.

{Function} outputType

Provides a function to customize the type in the output.

{Function} outputMessage

Provides a function to customize the message in the output.

{Function} generateMessage

Provides a function that generate the message to be outputted. It combines other internal methods for generate the output (as .isPrintable or .colorize) and normally you are not interested in the definition of it, but you can provide it as option as well.

{Function} generateTypeMessage

Provides a function used to generate the type message.

.push({String} <type>, {String} <message>)

Store a message of given type internally.

.add({String} <type>, {String} <message>)

Store a message of given type internally and also output it.

For each level you have a function following the pattern:

.print()

Prints all messages internally stored.

.[loglevel]({String} <message>)

For each log level that you declared in the constructor (or the default log levels provides by the library if you don't declare nothing) will be created a function with the same name to output a message with these log level.

License

MIT © Kiko Beats


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.