Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a debug mode #11

Open
btkostner opened this issue Feb 16, 2021 · 6 comments
Open

Add a debug mode #11

btkostner opened this issue Feb 16, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@btkostner
Copy link

Inspired from the Google Analytics debugging, it would be nice to see what events are being sent.

Detailed Description

Basically, add a console.debug statement in sendEvent that would output the event name and all the parameters it's sending to Plausible.

Context

This would be similar to going to the browser network tab, filtering to your Plausible domain, and going through all of the request data. Just easier. At the same time, I can see this being just gravy and adding to the bundle size.

Possible Implementation

Simply adding an option to PlausibleInitOptions and an if statement to sendEvent.

@btkostner btkostner added the enhancement New feature or request label Feb 16, 2021
@ukutaht
Copy link
Contributor

ukutaht commented Feb 23, 2021

I like the idea.

I wonder if there's prior art in including debug code in JS that is elided for production builds? Even if it's included in the production build it probably wouldn't add that much weight.

@yordis
Copy link

yordis commented Oct 31, 2021

I wonder if there's prior art in including debug code in JS that is elided for production builds?

The situation of logger has always been annoying. You can either decide to drop the logs altogether by doing dead-code elimination (except that most of the time you rely on tools for that),

Or,

Shameful plug: https://github.com/straw-hat-team/logger

You can create a logger instance in plausible and let people pass multiple handlers, which means they can always add the handlers based on the environments.

I added https://github.com/straw-hat-team/logger/blob/6636837f12f31949467e722d653f9d658aef2189/src/log-handler.ts#L41 in order to check to enable in production the logs if some developer is having trouble, you would do in the console:

globalThis.STRAW_HAT_GLOBALS = {
  logger: {
    level: 5 // Error
  } 
}

Or, expect an interface of the logger https://github.com/straw-hat-team/logger/blob/dcfbe92c57ba26ee7d342b2c044234dcfcc9a7d3/src/types.ts#L7, and pass a noop-logger https://github.com/straw-hat-team/logger/blob/f3b5533e75741a0451053418e92e17123eca52bf/src/noop-logger.ts#L3

The package is small enough so may be an option (maybe they are some trick to make it even smaller, not sure, PR welcome)

@ukutaht
Copy link
Contributor

ukutaht commented Nov 1, 2021

@yordis Thanks, the project looks neat!

Do you really need 8 log levels? :) I've always been happy with just DEBUG, INFO, WARN, ERROR

The script here is so small that I think all we really need is a single flag: debug either on of off.

@yordis
Copy link

yordis commented Nov 1, 2021

@ukutaht I am following Elixir steps on this one ;) https://github.com/elixir-lang/elixir/releases/tag/v1.11.0

Following Elixir v1.10, we have further integrated with Erlang's new logger by adding four new log levels: notice, critical, alert, and emergency, matching all log levels found in the Syslog standard

I am rather in line with Syslog and obviously ignore some of the levels on the web, but I don't see an issue with alignment on it

Also, you could use it in the backend if you would like to, the package is not bound to the browser environment.

@yordis
Copy link

yordis commented Nov 1, 2021

The script here is so small that I think all we really need is a single flag: debug either on or off.

Right, that is what I thought after I saw the compiled version LOL, but as I said, if I can pass my own logger (which is why you could take an interface), then it doesn't matter much.

Maybe create a tiny interface instead of 8 levels, from my perspective, it all depends of the implementation of the logger. 8 function declarations are like bytes that wouldn't matter that much unless you definitely want to save every single byte, then, just reduce the object to a function

type Logger = ()=> void

@ukutaht
Copy link
Contributor

ukutaht commented Nov 2, 2021

@ukutaht I am following Elixir steps on this one ;) https://github.com/elixir-lang/elixir/releases/tag/v1.11.0

Oh thanks for that, I didn't even know there were so many levels in Elixir :)

type Logger = ()=> void

Yeah that seems nice and simple, I like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants