log_parser
This commit is contained in:
23
elixir/log-parser/lib/log_parser.ex
Normal file
23
elixir/log-parser/lib/log_parser.ex
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
Reference in New Issue
Block a user