Skip to content

akreienbring/js-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-log

A simple logging utility for javascript

Why another javascript logger?

The answer is simple: Searching up and down the net I couldn't find one that fullfilled my need. I was looking for a logging utility that creates readable (grouped) output AND maintains the original console context.

That means that the information where the output was logged can still be examined in the debugging console of the browser. Sounds simple but I ended up using javascript proxies for that purpose and intercepted calls to the logger... Long story short: I had to follow a steep learning curve :-)
Maybe this little repo speeds up the work of other javascript developers.

What can you do with it?

Just download the js file and import it into your project:

import {Logger} from "./js-log.js";

Then create a new instance of a Logger like this:

const logger = Logger.getClassLogger("App");

A ClassLogger is meant to be a logger for a class / module of your application.
In contrast a FunctionLogger can be used to output what happens in a certain function of your class. Create one like this:

createThePanel(){  
    const logger = Logger.getFunctionLogger("App", "createThePanel");

Here's some sample output:
sample

You can easily disable / enable loggers like this:

Logger.disable("App");  
Logger.enable("App");

Or you choose to disable / enable all loggers:
Logger.disableAll();
Logger.enableAll();

Finally replace all your "console.log / .error / .info / .debug / .warn" statements with their

logger.log / .error / .info / .debug / .warn

counterparts.

Thats it! Happy logging!

Feb, 2020
André Kreienbring

About

A simple logging utility for javascript

Resources

License

Stars

Watchers

Forks

Packages

No packages published