elixir Logger for lists, tuples, etc

*爱你&永不变心* 提交于 2019-12-22 01:40:44

问题


I can use the elixir logger for inspecting strings

 > str = "string"
 > Logger.info "Here is a #{str}"
 [info] Here is a string

But when I log a list, it doesn't look pretty

 > list = [1,2,3,4,5]
 > Logger.info "Here is a list: #{list}"
 [info] Here is a list: ^A^B^C^D^E^F

When I log keyword list, it errors

 > kwl = [a: "apple", b: "banana"]
 > Logger.info "Here is a keyword list: #{kwl}"
   ** (ArgumentError) argument error
   (stdlib) :unicode.characters_to_binary([a: "apple", b: "banana"])
   (elixir) lib/list.ex:555: List.to_string/1

How do you logger lists, tuples and data types other than strings in Elixir?


回答1:


Your best bet is to use Logger.info "Here is some thing: #{inspect thing}". This way even if thing doesn't implement the String.Chars protocol, you still get something useful.



来源:https://stackoverflow.com/questions/28951208/elixir-logger-for-lists-tuples-etc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!