log_bench 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3d418b0832252146580022464c8b6401766ee056fb89642c42840d723a835e9
4
- data.tar.gz: 8f98119ed45ffe24bbffc947388598dd90be1643ed87b25bb1981e3e81effcd5
3
+ metadata.gz: 2129cbf1d3b38903693c9f13efc70a1d01ab73b668796461a30e46793e6922e6
4
+ data.tar.gz: 8bc054a8e475485ef2023bf66e30db6353dbfe66cf403a809369723a8ff01f0b
5
5
  SHA512:
6
- metadata.gz: 47681831e5f88acea414d1f1825849ce715a4b227e9180c3d290e98de6571ca886c26e889cb053c32dd267bd80a7ae32ca9a2f36286767afb238c754953382e3
7
- data.tar.gz: b261d76dd28d336a516f3245e6533551e6d6003e743ffc774686f12a7ef6b48852caf90eb8cc516ba569a47cea5644d08b41e9e4e645bb9181e456746099c371
6
+ metadata.gz: a16cd16974c7c83bde07265c51ffcbf77f6c809a19cbdc0206e3613694a89d01a8abab9086ee5a2700be7ee02f2a8c51f961cc711013fa3149e05e9024daa805
7
+ data.tar.gz: 210d660288a5e921035d51926588e830d8bc0ad3c890a2c68c64455f54b38a5c02b240e774ec8331b1d79712bcd595ed3ff5165d2d04a0e8379152dec5c5e2e9
@@ -52,12 +52,12 @@ module LogBench
52
52
 
53
53
  def handle_filter_input(ch)
54
54
  case ch
55
- when 10, 13, 27
55
+ when 10, 13, 27 # Enter, Return, Escape
56
56
  state.exit_filter_mode
57
- when KEY_UP, "k", "K"
57
+ when KEY_UP
58
58
  state.exit_filter_mode
59
59
  state.navigate_up
60
- when KEY_DOWN, "j", "J"
60
+ when KEY_DOWN
61
61
  state.exit_filter_mode
62
62
  state.navigate_down
63
63
  when 127, 8 # Backspace
@@ -37,7 +37,7 @@ module LogBench
37
37
 
38
38
  private
39
39
 
40
- attr_accessor :log_file_path, :state, :screen, :monitor, :input_handler, :renderer
40
+ attr_accessor :log_file_path, :log_file, :state, :screen, :monitor, :input_handler, :renderer
41
41
 
42
42
  def find_log_file(path)
43
43
  candidates = [path] + DEFAULT_LOG_PATHS
@@ -67,8 +67,9 @@ module LogBench
67
67
  end
68
68
 
69
69
  def load_initial_data
70
- log_file = Log::File.new(log_file_path)
70
+ self.log_file = Log::File.new(log_file_path)
71
71
  state.requests = log_file.requests
72
+ log_file.mark_as_read!
72
73
  end
73
74
 
74
75
  def check_for_updates
@@ -81,7 +82,7 @@ module LogBench
81
82
  end
82
83
 
83
84
  def start_monitoring
84
- self.monitor = Monitor.new(log_file_path, state)
85
+ self.monitor = Monitor.new(log_file, state)
85
86
  monitor.start
86
87
  end
87
88
 
@@ -3,8 +3,8 @@
3
3
  module LogBench
4
4
  module App
5
5
  class Monitor
6
- def initialize(log_file_path, state)
7
- self.log_file_path = log_file_path
6
+ def initialize(log_file, state)
7
+ self.log_file = log_file
8
8
  self.state = state
9
9
  self.running = false
10
10
  end
@@ -23,11 +23,9 @@ module LogBench
23
23
 
24
24
  private
25
25
 
26
- attr_accessor :log_file_path, :state, :thread, :running
26
+ attr_accessor :log_file, :state, :thread, :running
27
27
 
28
28
  def monitor_loop
29
- log_file = Log::File.new(log_file_path)
30
-
31
29
  loop do
32
30
  break unless running
33
31
 
@@ -14,6 +14,8 @@ module LogBench
14
14
  self.state = state
15
15
  self.scrollbar = scrollbar
16
16
  self.ansi_renderer = ansi_renderer
17
+ self.cached_lines = nil
18
+ self.cache_key = nil
17
19
  end
18
20
 
19
21
  def draw
@@ -26,7 +28,7 @@ module LogBench
26
28
 
27
29
  private
28
30
 
29
- attr_accessor :screen, :state, :scrollbar, :ansi_renderer
31
+ attr_accessor :screen, :state, :scrollbar, :ansi_renderer, :cached_lines, :cache_key
30
32
 
31
33
  def draw_header
32
34
  detail_win.setpos(0, 2)
@@ -54,7 +56,7 @@ module LogBench
54
56
  request = state.current_request
55
57
  return unless request
56
58
 
57
- lines = build_detail_lines(request)
59
+ lines = get_cached_detail_lines(request)
58
60
  visible_height = detail_win.maxy - 2
59
61
 
60
62
  adjust_detail_scroll(lines.size, visible_height)
@@ -95,6 +97,30 @@ module LogBench
95
97
  end
96
98
  end
97
99
 
100
+ def get_cached_detail_lines(request)
101
+ current_cache_key = build_cache_key(request)
102
+
103
+ # Return cached lines if cache is still valid
104
+ if cached_lines && cache_key == current_cache_key
105
+ return cached_lines
106
+ end
107
+
108
+ # Cache is invalid, rebuild lines
109
+ self.cached_lines = build_detail_lines(request)
110
+ self.cache_key = current_cache_key
111
+ cached_lines
112
+ end
113
+
114
+ def build_cache_key(request)
115
+ # Cache key includes factors that affect the rendered output
116
+ [
117
+ request.request_id,
118
+ request.related_logs.size,
119
+ state.detail_filter.display_text,
120
+ detail_win.maxx # Window width affects text wrapping
121
+ ]
122
+ end
123
+
98
124
  def build_detail_lines(request)
99
125
  lines = []
100
126
  max_width = detail_win.maxx - 6 # Leave margin for borders and scrollbar
@@ -65,6 +65,10 @@ module LogBench
65
65
  ::File.mtime(path)
66
66
  end
67
67
 
68
+ def mark_as_read!
69
+ self.last_position = size
70
+ end
71
+
68
72
  private
69
73
 
70
74
  attr_writer :path, :last_position
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogBench
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_bench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamín Silva