I’m just trying to make the functional core of my application as pure as possible, following the functional core, imperative shell pattern.
One problem I have is logging. Consider this code deep in the core:
case var do
:foo ->
{:ok, "foo"}
:bar ->
{:error, "bar"}
end
So one of the possible return values of the core would be{:error, "bar"}
. This error is just data, so I can easily write a test, that’s good. But I would also like to log it. I could:
- write a handler in the shell that matches on all errors and logs them. But then I’m missing Logger’s metadata.
- I could prepend each
{:error, ...}
with a call to Logger
What I’d rather do is sth like this:
- core:
{:error, {"bar", Logger.get_all_meta([custom_meta: :my_metadata])}}
- shell: use this data to log at one place outside the core with correct metadata