Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
df08191
FAQM-1581/FAQM-1582-multiple app filter support and args support in l…
Jan 6, 2025
dd4a176
FAQM-1584/FAQM-1582- goto date entry support and launch command support
Jan 6, 2025
3923414
unit test cases addition and minor feature corrections
Jan 8, 2025
b1a3331
FAQM-1584-minor feature corrections and comments
Jan 8, 2025
73d66de
Merge pull request #4 from FellowesInc/FAQM-1743-rebase-to-nerves-repo
Shivaji-Dhepale Jan 31, 2025
3f28e75
Merge branch 'nerves-project:main' into FAQM-1584-goto-date-support
Shivaji-Dhepale Feb 11, 2025
25e4a1f
Merge branch 'nerves-project:main' into FAQM-1581-app-list
Shivaji-Dhepale Feb 11, 2025
b85ca65
Addition of New Command for Date Entry Navigation
Feb 11, 2025
af7a1fd
Enhancement to existing application list command
Feb 11, 2025
c303c99
minor mix format error fixing
Feb 14, 2025
c5cc6e5
command concatenation support in TUI
Feb 18, 2025
6f28396
mix format check
Feb 18, 2025
2abca7e
optional-ringlogger-launch-cmd-argument
Feb 18, 2025
29f677d
addressed review comments
Feb 21, 2025
287b52b
Merge branch 'main' into FAQM-1581-app-list
Shivaji-Dhepale Apr 28, 2025
0a2af1a
mix format check
Shivaji-Dhepale Apr 28, 2025
6400916
Merge branch 'main' into Optional-Initial-Command-String-for-Launch-C…
Shivaji-Dhepale Apr 28, 2025
7713fe1
removed merge conflict
May 20, 2025
762b31f
Merge pull request #6 from FellowesInc/Optional-Initial-Command-Strin…
Shivaji-Dhepale May 22, 2025
73da89c
Merge branch 'main' into FAQM-1584-goto-date-support
Shivaji-Dhepale May 22, 2025
c95d979
Merge pull request #8 from FellowesInc/FAQM-1584-goto-date-support
Shivaji-Dhepale May 22, 2025
33a2194
Merge branch 'main' into command-concatenation-support-in-viewer
Shivaji-Dhepale May 23, 2025
e061d46
Merge pull request #7 from FellowesInc/command-concatenation-support-…
Shivaji-Dhepale May 23, 2025
e69e936
Merge branch 'main' into FAQM-1581-app-list
Shivaji-Dhepale May 23, 2025
70b2547
mix formatter compliance
May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/ring_logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ defmodule RingLogger do

alias RingLogger.Autoclient
alias RingLogger.Server
alias RingLogger.Viewer

@typedoc "Option values used by the ring logger"
@type server_option() ::
Expand Down Expand Up @@ -193,11 +194,17 @@ defmodule RingLogger do
@spec tail(non_neg_integer(), client_options()) :: :ok
def tail(n, opts), do: Autoclient.tail(n, opts)

@doc """
Starts the Ring Logger Viewer TUI app on the current prompt with intial arguments
"""
@spec viewer(String.t()) :: :ok
defdelegate viewer(cmd_string), to: Viewer, as: :view

@doc """
Starts the Ring Logger Viewer TUI app on the current prompt
"""
@spec viewer() :: :ok
def viewer(), do: RingLogger.Viewer.view()
defdelegate viewer(), to: Viewer, as: :view

@doc """
Reset the index into the log for `next/1` to the oldest entry.
Expand Down
33 changes: 25 additions & 8 deletions lib/ring_logger/viewer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ defmodule RingLogger.Viewer do
@level_strings ["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"]

@microsecond_factor 1_000_000

@seconds_in_year 365 * 24 * 60 * 60
@seconds_in_month 30 * 24 * 60 * 60
@seconds_in_week 7 * 24 * 60 * 60
@seconds_in_day 24 * 60 * 60
@seconds_in_hour 60 * 60
@seconds_in_minute 60

@spec view() :: :ok
def view() do
@spec view(String.t()) :: :ok
def view(cmd_string \\ "") do
screen_dims = get_screen_dims()

if screen_dims.w <= @min_width do
Expand All @@ -62,9 +61,7 @@ defmodule RingLogger.Viewer do
raise "Sorry, your terminal needs to be at least #{@min_height} rows high to use this tool!"
end

IO.puts("Starting RingLogger Viewer...")

@init_state |> get_log_snapshot() |> loop()
parse_launch_cmd(cmd_string, @init_state) |> get_log_snapshot() |> loop()
end

@doc """
Expand All @@ -88,6 +85,11 @@ defmodule RingLogger.Viewer do
# apply_command_parser/3 returns state by applying single filter
defp apply_command_parser(cmd_char, cmd, state) do
case {cmd_char, cmd, state} do
{"l", cmd, state} -> set_log_level(cmd, state)
{"a", cmd, state} -> add_remove_app(cmd, state)
{"r", _cmd, _state} -> %{@init_state | current_page: 0}
{"g", cmd, state} -> add_remove_grep(cmd, state)
{"q", _cmd, state} -> %{state | running: false}
{"d", cmd, state} -> add_time_log(cmd, state)
_ -> state
end
Expand Down Expand Up @@ -339,13 +341,21 @@ defmodule RingLogger.Viewer do
inspect_entry(index, state, current_logs)
state
else
first_char = String.at(cmd_string, 0) |> String.downcase()
command(first_char, cmd_string, state)
handle_commands(cmd_string, state, String.contains?(cmd_string, ";"))
end

%{new_state | last_cmd_string: cmd_string}
end

defp handle_commands(cmd_string, state, true) do
parse_launch_cmd(cmd_string, state) |> get_log_snapshot()
end

defp handle_commands(cmd_string, state, false) do
cmd = String.at(cmd_string, 0) |> String.downcase()
command(cmd, cmd_string, state)
end

defp command(cmd_exit, _cmd_string, state) when cmd_exit in ["e", "q"] do
%{state | running: false}
end
Expand Down Expand Up @@ -531,6 +541,12 @@ defmodule RingLogger.Viewer do
%{state | applications_filter: [app_atom | state.applications_filter], current_page: 0}
end

# accept the series of applications if entered by user and convert them to atoms list
[_cmd | app_strings] ->
app_atom = Enum.map(app_strings, &String.to_existing_atom/1)

%{state | applications_filter: app_atom, current_page: 0}

_ ->
state
end
Expand Down Expand Up @@ -567,6 +583,7 @@ defmodule RingLogger.Viewer do
"\t(g)rep [regex/string] - regex/string search expression, leaving argument blank clears filter.\n",
"\t(l)evel [log_level] - filter to specified level (or higher), leaving level blank clears the filter.\n",
"\t(a)pp [atom] - adds/remove an atom from the 'application' metadata filter, leaving argument blank clears filter.\n",
"\t(;)concat commands [example usage] - a telit_modem; g some_name \n",
"\t(d)ate [start_time] [duration] - show entries at specified time and duration. [ex. d 2024-12-25 10:20:01 P0Y0M0W0DT0H1M0S]\n",
"\t0..n - input any table index number to fully inspect a log line, and view its metadata.\n",
"\t(e)xit or (q)uit - closes the log viewer.\n",
Expand Down
25 changes: 25 additions & 0 deletions test/ring_logger/viewer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ defmodule RingLogger.ViewerTest do
{:ok, %{state: nil}}
end

test "a command with single application using parse_launch_cmd/2" do
cmd_string = "a blofeld_firmware"
state = Viewer.parse_launch_cmd(cmd_string, @init_state)
assert [:blofeld_firmware] == state.applications_filter
end

test "a command with multiple applications using parse_launch_cmd/2" do
cmd_string = "a blofeld_firmware telit_modem nil $kmsg"
state = Viewer.parse_launch_cmd(cmd_string, @init_state)
assert [:blofeld_firmware, :telit_modem, nil, :"$kmsg"] == state.applications_filter
end

test "Viewer.parse_launch_cmd/2 with multiple commands ; separated" do
cmd_string = "a telit_modem; l debug"
state = Viewer.parse_launch_cmd(cmd_string, @init_state)
assert [:telit_modem] == state.applications_filter
assert :debug == state.lowest_log_level
end

test "Viewer.parse_launch_cmd/2 with invalid format" do
cmd_string = "r l debug; a"
state = Viewer.parse_launch_cmd(cmd_string, @init_state)
assert [] == state.applications_filter
end

test "goto date command without duration argument [d 2024-12-25] " do
cmd_string = "d 2024-12-25"
state = Viewer.parse_launch_cmd(cmd_string, @init_state)
Expand Down