#TIL elixir 1.11에 추가된 구조화된 로깅(keyword, map)
keyword, map을 변환할 필요없이 로거 인자로 넘길 수 있다. 편해졌다.
Logger.info([new_user: user_id, account_type: :admin])
Logger.info(%{new_user: user_id, account_type: :admin})
11:03:47.330 [info] [new_user: 5, account_type: :admin]
섞어 쓸 수 있을까?
Logger.error("We have a problem", [error_code: :pc_load_letter])
안타깝게도 이런 형식은 안 된다. 두 번째 인자는 metadata로 들어간다.
Logger.error([msg: "We have a problem", error_code: :pc_load_letter])
그래서 메시지까지 구조화해서 로깅했다.
On the footsteps of v1.10, we have further integrated with Erlang’s new logger by adding four new log levels: notice, critical, alert, and emergency, matching all log levels found in the Syslog standard. The Logger module now supports structured logging by passing maps and keyword lists to its various functions. It is also possible to specify the log level per module, via the Logger.put_module_level/2 function. Log levels per application will be added in future releases.
Elixir v1.11 released - The Elixir programming language - elixir-lang.org
1.11에 추가됐다. 1.19rc가 나온 지금 한참 전에 추가된 피처다. 1.10 버전을 엄청나게 오래 써서 그런지 여기에 멈춰있었다.