My Task
runs some long and heavy computations, including downloading tarball, unpacking it, calling some external programs and so on. I’d like to log this process and Logger with logger_file_backend seems like a nice fit.
In Task
“body” I have following code:
Logger.add_backend({LoggerFileBackend, id}) # id is string
Logger.configure_backend({LoggerFileBackend, id},
path: Path.join(dir, "output/run.log"),
level: :info,
metadata_filter: [task: id]
)
# actual work...
Logger.remove_backend({LoggerFileBackend, id})
On compilation I get this warning:
warning: passing non-atom as application env key is deprecated, got: "1710.07035"
(elixir 1.11.3) lib/application.ex:621: Application.get_env/3
(logger_file_backend 0.0.11) lib/logger_file_backend.ex:175: LoggerFileBackend.configure/3
(logger_file_backend 0.0.11) lib/logger_file_backend.ex:21: LoggerFileBackend.init/1
(stdlib 3.15) gen_event.erl:523: :gen_event.server_add_handler/4
(stdlib 3.15) gen_event.erl:369: :gen_event.handle_msg/6
(stdlib 3.15) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
So internal implementation uses :gen_event
which demands an atom; problem is that there’re potentially infinite number of ids. Actually using atoms is not a big deal since I won’t be running million tasks at once, but still it feels kinda hacky. Are there other avenues to capture logs to file?