Giter Site home page Giter Site logo

geothird / leo-logger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leoplatform/leo-logger

0.0 1.0 0.0 7 KB

Such an awesome logger that we had to break it out from the LEO SDK and make it its own project!

License: MIT License

JavaScript 100.00%

leo-logger's Introduction

Leo-Logger

Such an awesome logger that we had to break it out from the LEO SDK and make it its own project!

Available methods

  • sub
  • info
  • json
  • time
  • timeEnd
  • log
  • debug
  • error
  • configure

Available configuration options

  • a = all
  • t = time
  • i = info
  • d = debug
  • e = error
  • T = printTimestamp

Usage example:

export LEO_LOGGER='/.*/d'

Working with namespaces

You can log logs for specific namespaces by passing a string when requiring the leo-logger. Example:

const logger = require('leo-logger')('my-special-namespace');

When you use a namespace, logging works the same, but the output will be prefixed with the namespace:

logger.log('My namespaced log');
// outputs: my-special-namespace my namespaced log

If you want to display logs for certain namespaces only, you can adjust LEO_LOGGER to match the namespace.

# Example outputting all logs for my-special-namespace
export LEO_LOGGER='/my\-special\-namespace/a'

You may notice in the previous example how it appears we’re using regex. This allows you to employ more powerful namespace logging. As an example, let’s say you have a shopping cart, and you want to have logs specific to the checkout process. Each of the checkout pages would include the leo-logger. I'm going to use an example of 2 checkout pages, which would look like this:

const logger = require('leo-logger')('checkout-payment');
const logger = require('leo-logger')('checkout-process-order');

Then if you want to display logs for the process-order page, you would do this:

export LEO_LOGGER='/checkout\-process\-order/a'

But if you want to display logs for all checkout pages, you can use the power of regex to select everything starting with “checkout”:

export LEO_LOGGER='/checkout.*/a'

Loggers

logger.log('my logged message');
logger.info('my info');
logger.debug('just some debugging code');

Timers

// start a timer
logger.time('myTimer');
// stop a timer
logger.timeEnd('endTimer');

To-Do

More documentation with examples with code and output.

Support

Want to hire an expert, or need technical support? Reach out to the Leo team: https://leoinsights.com/contact

leo-logger's People

Contributors

handyman avatar

Watchers

 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.