All Projects → achojs → Acho

achojs / Acho

Licence: mit
The Hackable Log

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Acho

Cocoadebug
iOS Debugging Tool 🚀
Stars: ✭ 3,769 (+1894.18%)
Mutual labels:  logging, log, logger, debugger, debug
Logcat
Android 日志打印框架,在手机上可以直接看到 Logcat 日志啦
Stars: ✭ 189 (+0%)
Mutual labels:  logging, log, logger, debugger, debug
Ios Sdk
AppSpector is a debugging service for mobile apps
Stars: ✭ 56 (-70.37%)
Mutual labels:  logging, logger, debugger, debug
debug.js
Debugger of JavaScript, by JavaScript, for JavaScript
Stars: ✭ 19 (-89.95%)
Mutual labels:  debugger, log, logger, debug
Serverless Es Logs
A Serverless plugin to transport logs to ElasticSearch
Stars: ✭ 51 (-73.02%)
Mutual labels:  logging, log, logger
Fliplog
fluent logging with verbose insight, colors, tables, emoji, filtering, spinners, progress bars, timestamps, capturing, stack traces, tracking, presets, & more...
Stars: ✭ 41 (-78.31%)
Mutual labels:  logging, log, debug
Plog
Portable, simple and extensible C++ logging library
Stars: ✭ 1,061 (+461.38%)
Mutual labels:  logging, log, logger
Loguru
Python logging made (stupidly) simple
Stars: ✭ 10,510 (+5460.85%)
Mutual labels:  logging, log, logger
Simplog
A simple logger. No dependencies, no special features, just logging.
Stars: ✭ 17 (-91.01%)
Mutual labels:  simple, logging, logger
Yii2 Psr Log Target
Yii 2.0 log target that is able to write messages to PSR-3 compatible logger
Stars: ✭ 58 (-69.31%)
Mutual labels:  logging, log, logger
React Native Logs
Performance-aware simple logger for React-Native with namespaces, custom levels and custom transports (colored console, file writing, etc.)
Stars: ✭ 84 (-55.56%)
Mutual labels:  logging, logger, debug
Wormholy
iOS network debugging, like a wizard 🧙‍♂️
Stars: ✭ 2,010 (+963.49%)
Mutual labels:  logging, logger, debugger
Loglevelnext
A modern logging library for Node.js that provides log level mapping to the console
Stars: ✭ 33 (-82.54%)
Mutual labels:  logging, log, logger
Gollum
An n:m message multiplexer written in Go
Stars: ✭ 883 (+367.2%)
Mutual labels:  logging, log, logger
Easylogger
An ultra-lightweight(ROM<1.6K, RAM<0.3k), high-performance C/C++ log library. | 一款超轻量级(ROM<1.6K, RAM<0.3k)、高性能的 C/C++ 日志库
Stars: ✭ 1,968 (+941.27%)
Mutual labels:  logging, log, logger
Android Filelogger
A general-purpose logging library with built-in support to save logs to file efficiently.
Stars: ✭ 70 (-62.96%)
Mutual labels:  logging, log, logger
Serverlog
A simple, practical and innovative Node.js log library that enables you to view logs in Chrome dev tools and browser Console.
Stars: ✭ 117 (-38.1%)
Mutual labels:  logging, log, logger
Android Remote Debugger
A library for remote logging, database debugging, shared preferences and network requests
Stars: ✭ 132 (-30.16%)
Mutual labels:  logging, logger, debug
gxlog
A concise, functional, flexible and extensible logger for go.
Stars: ✭ 65 (-65.61%)
Mutual labels:  log, logger, logging
Ololog
A better console.log for the log-driven debugging junkies
Stars: ✭ 141 (-25.4%)
Mutual labels:  logging, log, debug

acho

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

The <hackeable /> Log

Features

  • Different log levels skins.
  • Beauty object interpolation.
  • Diff & log trace support.
  • Easy to customize, easy to hack.

Install

npm install acho

Usage

Logging levels

Examples


acho

The first thing you need to do is create a new log instance:

const acho = require('acho')
const log = acho()

Then you can print a log based on the level:

const acho = require('acho')
const log = acho()

acho.info('hello world')

All methods are chainables:

const acho = require('acho')
const log = acho()

acho
  .info('hello world')
  .error('something bad happens')

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

  • fatal : Display calls to .fatal() messages.
  • error : Display calls to .fatal(), .error() messages.
  • warn : Display calls from .fatal(), .error(), .warn() messages.
  • info : Display calls from .fatal(), .error(), .warn(), info() messages.
  • debug : Display calls from .fatal(), .error(), .warn(), info(), debug() messages.

Additionally exists two special levels:

  • muted : Avoid all output.
  • all : Allow print all message types.

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

const acho = require('acho')
const log = acho({ level: 'debug' })

or at runtime:

log.level = 'debug'

Internal Store

Sometimes, when you are interacting with a logger you need to store the logs to be used later instead of print all of them.

We define .push as accumulator for store the log internally:


acho

const acho = require('acho')
const log = acho()

log.push('success', 'good job', 'well done', 'great!')
console.log(log.messages.success)

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


acho

or you can retrieve the logs programatically from the internal storage at acho.messages

The method .add combine .push and .print actions in one: It store the message internally but also print the log.


acho

log.add('info', 'this message is printed and stored')
console.log(acho.messages.info)

Formatters

Examples


acho

We use printf-style formatting. Below are the officially supported formatters:

Formatter Representation
%s String.
%d Number (both integer and float).
%j JSON serialization in one line
%J JSON pretty object in multiple lines
%% Single percent sign ('%'). This does not consume an argument.

By default, the %j is applied when you pass an object to be logged:

const acho = require('acho')
const log = acho()

log.info({ hello: 'world', foo: 'bar' })
// => 'info hello=world foo=bar'

If you want to use a different formatter, use printf markup:

const acho = require('acho')
const log = acho()

log.info('formatting with object interpolation %J', {
  hello: 'world',
  foo: 'bar',
  deep: {
    foo: 'bar',
    arr: [1, 2, 3, 4, 5]
  }
})

Customization

Examples

One of the acho compromise is be easy to adapt. You can completely customize all the library functionalities.

For example, suppose you want to add a timestamp before your logs:


acho

const acho = require('acho')

const log = acho({
  // Customize how to print the 'type' of each message
  outputType: type => `[${type}]`,

  // Customize how to print the message.
  // Add things before and/or after.
  outputMessage: message => `${Date.now()} :: ${message}`
})

acho.info('I am hungry')

That's all.

API

acho([options])

It creates a logger instance.

options

keyword

Type: string 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.

align

Type: string 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.

diff

Type: boolean Default: false

Prints trace between log from the same level. Specially useful to debug timings.

upper

Type: boolean Default: false.

Enable or disable print log level in upper case.

trace

Type: boolean|number Default: false.

Prints a numeric counter trace associated with each log line.

The value provided is the minimum quantity of time in milliseconds to consider print a different counter.

offset

Type: number Default: 2.

The amount of left whitespace between the property key and all of it's sub-properties.

This option is only applied under JSON pretty object in multiple lines (%J).

depth

Type: number Default: Infinity.

Colapses all properties deeper than specified by depth.

This option is only applied under JSON pretty object in multiple lines (%J).

level

Type: string 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.

transport

Type: function Default: console.log

Defines where write the log message.

types

Type: object

You can provide the types and priorities.

messages

Type: object

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.

print

Type: function

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

outputType

Type: function

Provides a function to customize the type in the output.

outputMessage

Type: function

Provides a function to customize the message in the output.

generateMessage

Type: function

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.

generateTypeMessage

Type: function

Provides a function used to generate the type message.

.push(<type>, <message>)

Store a message of given type internally.

type

Type: string

message

Type: string

.add(<type>, <message>)

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

type

Type: string

message

Type: string

For each level you have a function following the pattern:

.print()

Prints all messages internally stored.

.[loglevel](<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.

message

Type: string

License

acho © Kiko Beats, Released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @kikobeats

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].