24 lines
602 B
Elixir
24 lines
602 B
Elixir
defmodule LogParser do
|
|
def valid_line?(line) do
|
|
line =~ ~r/^\[DEBUG|INFO|WARNING|ERROR\]/u
|
|
end
|
|
|
|
def split_line(line), do: String.split(line, ~r/\<[\~\*\=\-]*\>/i)
|
|
|
|
def remove_artifacts(line), do: String.replace(line, ~r/end-of-line\d+/i, "")
|
|
|
|
def tag_with_user_name(line) do
|
|
if String.contains?(line, "User") do
|
|
map =
|
|
Regex.named_captures(
|
|
~r/^(?<type>\[\p{Lu}+\])(?<message>[\w\s]+User[\s\n]+(?<user>\S+)[\s\n]*.*)$/,
|
|
line
|
|
)
|
|
|
|
Enum.join(["[USER]", map["user"], map["type"] <> map["message"]], " ")
|
|
else
|
|
line
|
|
end
|
|
end
|
|
end
|