NLdoc.Test.Logs (NLdoc.Test v3.0.3)
View SourceThis module helps with capturing log output in tests.
Summary
Functions
For use with &ExUnit.CaptureLog.capture_log/2.
For parsing multiple lines of log.
Parsing a single line of log.
Parsing metadata.
Types
Functions
For use with &ExUnit.CaptureLog.capture_log/2.
Examples
iex> NLdoc.Test.Logs.opts()
[colors: [enabled: false], format: "$time $metadata[$level] $message\n", metadata: :all]
iex> NLdoc.Test.Logs.opts(format: "$message")
[colors: [enabled: false], metadata: :all, format: "$message"]
iex> NLdoc.Test.Logs.opts(level: :info)
[colors: [enabled: false], format: "$time $metadata[$level] $message\n", metadata: :all, level: :info]
For parsing multiple lines of log.
Examples
iex> "23:09:04.123 line=114 file=lib/ex_unit/capture_log.ex [info] hello this is a test\n" <>
...> "22:08:03.193 line=124 file=lib/ex_unit/capture_log.ex [error] Lorem, ipsum, dolor sit.\n"
...> |> NLdoc.Test.Logs.parse!()
[
{
"23:09:04.123",
%{"line" => "114", "file" => "lib/ex_unit/capture_log.ex"},
"info",
"hello this is a test"
},
{
"22:08:03.193",
%{"line" => "124", "file" => "lib/ex_unit/capture_log.ex"},
"error",
"Lorem, ipsum, dolor sit."
}
]
iex> NLdoc.Test.Logs.parse!("Not following format.")
** (RuntimeError) Log does not follow format: "Not following format."
Parsing a single line of log.
Examples
iex> "23:09:04.123 line=114 file=lib/ex_unit/capture_log.ex [info] hello this is a test"
...> |> NLdoc.Test.Logs.parse_line!()
{"23:09:04.123", %{"line" => "114", "file" => "lib/ex_unit/capture_log.ex"}, "info", "hello this is a test"}
iex> NLdoc.Test.Logs.parse_line!("Not following format.")
** (RuntimeError) Log does not follow format: "Not following format."
Parsing metadata.
Examples
iex> "23:09:04.123 hello=world service.name=nldoc_foo"
...> |> NLdoc.Test.Logs.parse_metadata()
%{"hello" => "world", "service.name" => "nldoc_foo"}