0.0.2 • Published 4 months ago

@danidoble/tracerlog v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

TracerLog

Zero dependency library to trace the log in the console.

Trace log for javascript console When you want to trace the log in the console, you can use this library. For example, you can trace the log in the console like this.

import TracerLog from "@danidoble/tracerlog";

const tracer = new TracerLog();
tracer.init();

Or if you want a common JS, you can do it like this.

<script src="tracerlog.js"></script>
<script>
    const tracer = new TracerLog();
    tracer.init();
</script>

So you can use the console of the browser to see the log as always.

console.log("Hello world");

If you want to get the current log, you can do it like this.

tracer.data; // here are an array with the logs.

By default, when the limit was reached, the log will dispatch an event of browser. So you can listen this event to save with your own code.

document.addEventListener("console:save", function (event) {
    // here you can save the log with your own code.
});

But if you want only one file with the log, you can use the property save_file.

tracer.save_file = true;
// when the limit was reached, the log will be saved in the file.

If you want to change the limit of logs before call to save it, you can do it like this. (by default limit is 300)

tracer.limit = 10;

If you want disable the console but preserve trace

tracer.console = false;

If you want save the log when you want, you can do it like this.

tracer.saveNow();

When the page is unloaded, the log will be saved automatically.

window.location.reload();
// before reload the page, the log will be saved.
0.0.2

4 months ago

0.0.1

4 months ago