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

Way to unset/remove log handlers? #24

Open
martinklepsch opened this issue Nov 14, 2022 · 5 comments
Open

Way to unset/remove log handlers? #24

martinklepsch opened this issue Nov 14, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@martinklepsch
Copy link
Contributor

Hey there :)

Finally found some time to play with this library and gotta say it's really nice how easy it is to add a custom logger.

During development in the REPL I sometimes wanted to remove all logging handlers just to have a "clean slate". I think there's a check to not add the same handler twice but with a REPL session my handler function might have changed and glogi might not be able to know that it's intended to replace an existing handler.

Is there a way to remove all handlers for a situation like this?

Thanks 🙌

@martinklepsch
Copy link
Contributor Author

And maybe relatedly: I'm seeing logs being printed in Node.js despite not having called any install method.

 [  0.163s] [app.server] {:server/starting {:port 3000}, :line 165}

The formatting looks like the very default of goog.log so maybe on Node there's already some default handlers in place when loading goog.log?

@plexus
Copy link
Member

plexus commented Nov 14, 2022

Martin! Long time no see :D

Remove all handlers (bit hacky, no better API for this at the moment. PR welcome to add a proper function for this)

(->> (goog.object/get lambdaisland.glogi/root-logger "__glogi_handlers__")
     keys
     (run! lambdaisland.glogi/remove-handler))

maybe on Node there's already some default handlers in place?

I don't think so, just started a Node based cljs repl and tried it out, doesn't log anything until I install a handler. Maybe you're loading another library that's adding a goog.log handler?

@martinklepsch
Copy link
Contributor Author

I don't think so, just started a Node based cljs repl and tried it out, doesn't log anything until I install a handler. Maybe you're loading another library that's adding a goog.log handler?

Ha! That was it indeed. Thanks for the pointer!

PR welcome to add a proper function for this

Do you think something like clear-handlers! to just remove all handlers like in your snippet would do the job?

I could also imagine that handlers are added with a key so when adding one with the same key, the old handler could be removed. From a 'trying this at the REPL' perspective this would be slightly better than clear-handlers! although that's also fine.

In addition I might also suggest to update the docs a bit to call out that the only-once part requires the handler function to remain exactly the same, which might not always be a given with REPLs / hot reload.

What do you think?

@plexus
Copy link
Member

plexus commented Nov 25, 2022

You're right, having a key similar to e.g. in add-watch would be more convenient, that's usually how I set up these kind of APIs, but I guess here I didn't. It would make sense to either add a three-arity version to add/remove-handler, or to add new functions that handle the case of adding by key.

Doc clarification is always appreciated, especially if the current docs tripped you up.

@alysbrooks alysbrooks added the enhancement New feature or request label Jul 15, 2023
@alysbrooks
Copy link
Member

I think this functionality is basic enough that we may want to work on it in the near future, so I'm leaving this open.

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