Giter Club home page Giter Club logo

megalogger's Introduction

megalogger

Minimalistic JavaScript logging framework, specifically usable for the browser console

Basic Configuration

Since typically logging output should be disabled in production apps, to see logging data you need to enable development mode and set a minimum log level, after which, messages would be shown.

You can do that by setting the following localStorage (or sessionStorage) variables:

// Set minimum log level - all levels can be found in MegaLogger.LEVELS
localStorage.minLogLevel = 10;

// Enable "development mode", to allow log messages to be shown in your console
localStorage.d = 1; // to disable it, just do a localStorage.removeItem("d");

Tip: To achieve maximum performance, the MegaLogger is in fact going to cache the localStorage/sessionStorage.* vars, so those SHOULD BE SET before calling ANY MegaLogger methods.

Basic Usage

One can simply make a logger using the MegaLogger constructor, but to take easiest advantage of nested loggers, it is preferred to use MegaLogger's factory function getLogger.

// Make logger instance.
var worldLogger = MegaLogger.getLogger('world');

// Log something on highest level.
worldLogger.log('Mega has got a new product!');

Output is:

2015-0-30 22:35:0.216 - world - LOG  Mega has got a new product!

To create nested loggers, reference the name of the parent logger.

// Make child logger instance.
var newZealandLogger = MegaLogger.getLogger('new_zealand', undefined, 'world');

// Log something.
newZealandLogger.warn('The new year is in summer.');

Output is:

2015-0-30 22:35:0.224 - world:new_zealand - WARN  The new year is in summer.

And another level.

// Make child logger instance.
var aucklandLogger = MegaLogger.getLogger('auckland', undefined, 'new_zealand');

// Log something.
aucklandLogger.info("We will bring the America's Cup home!");

Output is:

2015-0-30 22:35:0.224 - world:new_zealand:auckland - INFO  We will bring the America's Cup home!

megalogger's People

Contributors

lpetrov avatar diegocr avatar infinity0 avatar pohutukawa avatar

Stargazers

Abbi Christina Corcoran avatar  avatar Reed HHW avatar Carlos Venegas Arrabé avatar QODEBoT avatar Ornias Abezethibou avatar  avatar Heverton da Silva Cruz avatar Christian Ehrhardt avatar J. Austin Hughey avatar Juan Carlos Santiago avatar Gabriel Nunes avatar James Edward Lewis II avatar Nam PHAM avatar Alan Hardman avatar Aruna Tennakoon avatar  avatar Batuhan Göksu avatar sheena isawsum avatar  avatar Svetoslav Stanev avatar

Watchers

 avatar  avatar Artem S Vybornov avatar James Cloos avatar Andrei.d avatar Mathias Ortmann avatar Bram van der Kolk avatar  avatar  avatar  avatar Alexander Vassilev avatar Jonathan Purvis avatar André Meister avatar Sergio Hernández avatar  avatar  avatar

megalogger's Issues

String substitution problem

Apparently MegaLogger doesn't support string substitutions as the former console does.

I.e:

> MegaLogger.getLogger('foo').info('Adding %d tasks', 33)
< 2015-6-15 19:11:8.715 - foo - INFO Adding %d tasks 33

> console.info('Adding %d tasks', 33)
< Adding 33 tasks

Initially i thought it might be a problem while applying css styles, but it doesn't seem so:

> console.log("%cAdding %d tasks", "color: red; font-style: italic", 22);
< Adding 22 tasks

Cannot log in from OS X

I am unable to access Mega website from my MacBook Pro 2018 with touchpad that has Mac OS Mojave.I tried accessing the website with Safari, Fireforx and finally Chrome. However, it did not work. The system, as well as, browsers are updated.When I tried used VPN, following is the message I got:

MEGA failed to load because 
The file "https://eu.static.mega.co.nz/3/js/mega-1_fbd39ab7f39ba68514f9443ea5c30398025f2232051e4a48f9814e62ab7730cf.js" is corrupt.
Please click OK to refresh and try again.
If the problem persists, please try disabling all third-party browser extensions, update your browser and MEGA browser extension to the latest version. If that does not help, contact [email protected]
BrowserID: mozilla/5.0 (macintosh; intel mac os x 10_14_6) applewebkit/605.1.15 (khtml, like gecko) version/12.1.2 safari/605.1.15Static server: https://eu.static.mega.co.nz/3/Flipped to default static: noDate/time: 2019-09-07T06:38:26.149Z

The screenshot is also attached.Could you please guide me how can I overcome this difficulty?
On the contrary, I can login fro other Macbook Pro (without touchpad) from 2017 and iMac in 2018.

Thank you in advance,

Screenshot 2019-09-07 at 12 13 32 PM

MegaLogger.getLogger() inconsistency.

There is a problem when using MegaLogger.getLogger() and the provided parentLogger is different to one previously used.

For example:

var writeLogger = MegaLogger.getLogger('writer');
var readLogger = MegaLogger.getLogger('read');

function readIO() {
   var logger = MegaLogger.getLogger('I/O', {}, readLogger);
   logger.info('IO', arguments);
}

function writeIO() {
   var logger = MegaLogger.getLogger('I/O', {}, writeLogger);
   logger.info('IO', arguments);
}

readIO();
writeIO();

Both logger calls will output:

2015-6-12 21:9:4.161 - read:I/O - INFO IO Arguments { , 2 more… }
2015-6-12 21:9:4.162 - read:I/O - INFO IO Arguments { , 2 more… }

I think the way MegaLogger instaces are stored into _logRegistry must include the full/recursive path to the parentLogger, if any provided.

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.