espruino / EspruinoTools

JavaScript library of tools for Espruino - used for the Web IDE, CLI, etc.
Apache License 2.0
150 stars 90 forks source link

Feature: Loglevel #159

Open zentus opened 1 year ago

zentus commented 1 year ago

I'm not sure if this is something you want in the repo, if not, you can just close the PR.

This PR will:

Log levels:

The default loglevel will log everything, as it was previously. I tried to the best of my ability to use the most suitable logger method for each existing message, but there could be some messages that you may want to use another method for, I'll leave it for you to decide.

Examples:

# CLI
espruino --loglevel 0
// If you wish, you can test it out in the package of my fork
const espruino = require("@zentus/espruino");
const options = {
  logLevel: 0
};
espruino.init(options, () => console.log('init callback'));

// This should still work as well
// espruino.init(() => console.log('init callback'));
gfwilliams commented 1 year ago

Thanks! This looks like a good idea, and it's great it's not using another library for the logging.

My concern is that the Espruino IDE (espruino.com/ide / https://github.com/espruino/EspruinoWebIDE) uses this too, but I think that merging this would break that since it doesn't use index.js (that's just for the NPM library).

I think it would also break espruinotools (https://github.com/espruino/EspruinoAppLoaderCore/blob/893c2dbbe5a93fbb80d035a695663b4f4cca8875/lib/espruinotools.js) built from EspruinoTools with https://github.com/espruino/EspruinoWebIDE/blob/master/extras/create_espruinotools_js.sh

Would you be able to move the logger declaration into espruino.js? And then maybe try and give the two things above a quick check?

zentus commented 1 year ago

Ah, I see! Sure, I'll see what I can do.