Gladear
Hello ![]()
I’ve been looking for a way to do, put simply:
# Set metadata
Logger.metadata(meta1: :one)
# Execute code
# Remove metadata
Logger.metadata(meta1: nil)
I could have used this multiple times now. This method works fine, but when the `# Execute code` starts getting bigger, it’s easy to forget resetting the metadata at the end of it. Also, if an exception arises in the code and is caught, the metadata won’t get reset.
So I was wondering if a function `Logger.with_metadata([meta1: :one], fn → … end)` could be useful to integrate in `Logger`. Any thought about it? ![]()
Trending in Proposals: Ideas
We are seeing a lot of warning logs like this:
navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
I do not think that it would be useful to have in core, but as it is not that hard to implement on your own, then I do not think that it would be much of a problem.
I never had need for such thing, so I may be biased there.
dimitarvp
I basically rolled this out for myself during three previous consulting engagements. I suggest you do the same. No point having such a surface-level helper upstreamed. Do it like f.ex.
Repo.transaction– you pass a function / MFA to your helper and then do the cleanup after it is executed.krasenyp
As others already said, it’s a well-known functionality which is not very hard to implement. It’s very common in Common Lisp and it’s usually implemented with macros. If you want you could do the same and, in the end, have the following:
Gladear
I must say I’m a bit surprised
I quite expected the answer “nobody needs that, just do your own helper”, but if the answer is “yes, I do that a lot with my own implementation”, why not make it generic?
Indeed, the implementation is not really complicated, but I don’t think that makes the proposal invalid?
dimitarvp
A standard library’s API surface must be as small as possible by necessity. We don’t know for sure how it will evolve; maybe a next version will deprecate
Logger.metadataand replace it with something better. That would then lead to deprecating not one, but two functions. It complicates things. For reference, you can research why is Python such a Frankenstein monster of APIs. They added too much and too liberally back in the day and are now stuck with that legacy.A stdlib’s job is to give you building blocks, not ergonomic helpers.
hauleth
The problem I see there is that there is no clear semantic of how it should work. That is why it should be left up to the user.
Imagine situation like:
You say that
But if exception is raised, then system is in broken state anyway. So caller should know whether they need to reset the state to known form, not the callee.
That is why there is no clear way forward with that, as there is too many corner cases and the usability of such function is IMHO low, and implementing what you need is quite simple:
Gladear
Thanks for your answers, I’ll stick with our custom doing then
Have a nice day!