marcandre
Currently, ExUnit/CaptureLog.capture_log/2 returns the logs content captured but offers no possibility of returning any other result.
This makes it difficult to execute some_function we know should emit a log and both assert the log content and use the result of some_function.
One alternative is using the result within the function passed to capture_log, but that doesn’t compose well, or nest, and is problematic as the rest of the code could generate warnings, etc.
Another way is uses the Process dictionary, but that’s pretty ugly:
def with_log_matching(match, fun) do
assert ExUnit.CaptureLog.capture_log(fn ->
result = fun.()
Process.put(:log_capture_function_result, result)
end) =~ match
Process.delete(:log_capture_function_result)
end
test "something" do
result = with_log_matching("Hey, something strange is going on", fn ->
do_something_and_return(...)
end
assert do_something_else(result) == :ok
end
Could we have either a new function capture_log_and_result, or else a new option for capture_log like with_result: true or similar that would return {result, "captured log..."} instead of just the captured log?
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
:warning: Security advisory: Decimal DoS vulnerability
A vulnerability has been published for decimal where very large exponents can cau...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
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
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
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 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
axelson
Hi, while I’m not on the Elixir Core Team I wanted to chime in here to say that I think this is a good idea and it could simplify a common case of wanting to assert on the result of a statement as well as any logs that it generates. In particular I like the fact that it would reduce the visual code changes that are introduced when you want to assert on the log result. Currently you need to move your assert on the result into the
capture_loganonymous function which makes it a little less clear (generally I prefer to keep all the asserts at the top-level).In terms of the API I think that passing
with_result: truewould be a little more discoverable than a totally new function (but the core team may have different opinions of course).josevalim
+1 that this feature would be desired. I don’t like though using an option to change the return type. My suggestion would be to introduce a new function, as the mentioned
capture_log_and_resultor something more concise (could we replacecaptureby a word that would have such meaning?).hauleth
with_logsdimitarvp
But yep, human languages, especially English, are imperfect.
hauleth
Seize means of logging for the debugging class!
dimitarvp
And entomb the enemies of observability!
josevalim
I like with_log and with_io (from the equivalent capture_io). A PR is welcome!
marcandre
Awesome! Sounds really easy, I’ll do it
astery
Thank you, @marcandre, it’s already merged to master.
ityonemo
why not assert inside the nested fun?