Coder Social home page Coder Social logo

mikeerickson / logatim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sospedra/logatim

0.0 2.0 0.0 6.73 MB

Logatim is an isomorphic logger which implements log levels and ANSI styles.

Home Page: http://edravis.github.io/logatim/

License: ISC License

JavaScript 100.00%

logatim's Introduction

Build Status Coverage Status devDependency Status js-standard-style semantic-release npm Code Climate

Logatim is an isomorphic logger which implements log levels and ANSI 16 styles.

Finally you can use the same logger for the server and client side of your applications. Log for developers using colors, underlines, etc. in order to transform the terminal in an authentic debugger machine. And log for production managing exactly what have and what have not to be outputted.

Demo

If you're excited about this and want to try it right now you have 2 options:

  1. Copy the dist/logatim.umd.min.js and paste it on the browser console.
  2. Access to our official sandbox at Runnable.

Why?

I've been coding for a long time and I've always feel that we need a better approach to the logging issue. I've researched a lot about the available logger modules and I've even run a questionary about this topic. After this inquiry I think that the most suitable logger should combines these six elemental features:

  • 1. Free outputs: it should be able to stream the logs anywhere and to multiples targets at the same time.
  • 2. Levels: it should handle which levels should be printing or not.
  • 3. Styles: as a very useful resource while developing, it should implements colors, bolds, etc.
  • 4. Cross-platform: it should run in all the browsers and all the node versions. This includes the different Javascript specifications.
  • 5. Human-like: it shouldn't have been any learning curve, nor complex configurations; just require and go.
  • 6. Customizable: it should accept addons and plugins in order to keep a light and powerful core which can be extended for specific situations.

Installation

Choose one of the following options:

  1. Install it via npm: npm install logatim --save
  2. Download from the dist folder the stand-alone specification which fits better for you: var, commonjs, umd or amd. Note that the installation via npm uses the umd pattern so should work in all the environments.

Features

  • Logatim has colors, background colors and text styles.
  • Implements the five native console logging methods: trace, debug, info, warn and error. And also the silent mode.
  • Production ready for server and front-end sides. Learn one, implement everywhere.
  • Super lightweight, weighs in at 1.1KB minified and gzipped.
  • Implements human-like code style: logatim.green.bold.info('super sexy')
  • By using the native console object so you'll keep the stack trace and line numbers.
  • Works with multiple Javascript specifications: AMD, UMD, CommonJS and declaring a var directly.

Server support

  • All node versions via npm

Browser support

(Only the versions which had been introduced the console colors support. We cannot do magic... yet.)

  • Chrome
  • Edge
  • Firefox
  • Internet Explorer 8+
  • Opera
  • Vivaldi
  • Safari

Usage

The logatim API is tend to be extremely minimal and human-like. It has two different kind of options: the styling and the leveling ones. Logatim consists in:

Styles

const logatim = require('logatim')

logatim.blue.bgYellow.bold.info("It's like reading english")

// and the next print is completely independent; zero memories
logatim.green.info('No background color nor bold here')

// you can concat different styles
logatim.red('R').green('G').blue('B').info()

// also, of course you can print without any style
logatim.info("I'm a boring log")
  • The colors available are: black, red, green, yellow, blue, magenta, cyan, white, gray and grey (fixing humans).

  • The background colors available are: bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray and bgGrey.

  • The sets available are: bold, dim, italic, underline, blink, inverse, hidden, strikethrough (Almost no browser supports blink and inverse is not supported when printing on the browser's console).

asciicast

Levels

  • Use the five console native logging methods (aka levels):
const logatim = require('logatim')

// sorted from bottom in the bubbling logging scale
logatim.trace('Good for track pathways')
logatim.info('Good while developing')

// combine them, each log may differ depending on the channel
logatim
  .debug('Good for find errors')
  .warn('Good for production')
  .error('Good for performance')
  • And change the current level using the get/set methods:
const logatim = require('logatim')

logatim.getLevel() // by default is WARN
logatim.debug("I won't be printed") // because debug is lower than warn
logatim.setLevel('info')
logatim.debug("I'll be printed") // because debug is greater than info
  • Leveling also ensures that your logs don't break anything, even if there's not a console object (I'm staring at you IE) it will silent fallback to the safest print possible.

asciicast

Contributing

Please feel free to raise issues, make contributions or suggestions/requests. Remember that we follow standard code style and the continous integration pattern so any pull request should run the tests first.

git clone https://github.com/edravis/logatim.git
cd logatim
npm install
# edit logatim

# when done
npm test
npm run build
# send the PR, yaaay!

Todo list

If you feel that the force is strong in Logatim keep an eye to the todo list and maybe you find something you're willing to make ;)

  • Add the possibility to stream the output elsewhere than the console.
  • Add the CI for client-side environments.
  • Add Logatim to other source providers: bower, a CDN, etc.
  • Write the technical in-code documentation.
  • Allow custom prints depending on the level or globally.

Dat name, tho

Logatim comes from a combination of the words log and verbatim. The first one is obviously referred to the cutten trunk... lol no, it's for the coding logfiles. And the second one is a Latin term that can be translated as word for word. So, the term Logatim could be loosely translated as log for log.

License

The code is available under the ISC license.

Handcrafted by @sospedra_r / sospedra.me.

With contributions from:

  • [be the first here, make a PR!]

logatim's People

Contributors

sospedra avatar brunopgalvao avatar eanplatter avatar

Watchers

Mike Erickson avatar James Cloos 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.