log_bench 0.1.1 β†’ 0.1.3

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: b0d92e6c1086ecfd4c9905cf1bf5aaaa30491254665629cf52ac5b4a7e25e6b9
4
- data.tar.gz: 55bbebccbc40cd6de19af7a6cb16368196af421d69906911febabbf2f4732842
3
+ metadata.gz: 2984d376970a351d650b414fe6889976c1a9f0b3a572942784e007e974f5feaf
4
+ data.tar.gz: 63f7d6f0e7fcf52708434df60eb60f75990d3a8d05e136d76c41440b32e7542f
5
5
  SHA512:
6
- metadata.gz: a7f9d99742038dd519e135978620f5550517d9979bdae1f52c8ed52b79ce0b877cb36e97e5a33a05b9b6c53b7af38d61ac354807b9d3745aa5fcc3273e943f51
7
- data.tar.gz: 42bd3295bdd4fd628bfe145aead3c8d29918200aebf81420306d1ad79ef355904c6c8bd212f0dc03ed4afe4fc67d9d716003174ef3342726ff8c790062b21bbd
6
+ metadata.gz: f1792820588962d97177bacfed32730085829c5a9215cc2e4bd802d52c602023944e6b3d6ab47d118662550dce7c915a151d0c100b99549ada3a7533e50c7e85
7
+ data.tar.gz: e66b1b2e7075d2a26775f6b87a6348b084a56abeb10b6e27a7917a1f434f1f240d6a484557fb0c298bab7b258c307002347c16539ecbbdd638cf2c79c00048f3
data/README.md CHANGED
@@ -12,7 +12,6 @@ A powerful TUI (Terminal User Interface) for analyzing Rails application logs in
12
12
  - πŸ“ˆ **Performance insights** - duration, allocations, query analysis
13
13
  - 🎨 **Beautiful TUI** with syntax highlighting and ANSI color support
14
14
  - ⚑ **Fast parsing** of JSON-formatted logs
15
- - πŸ”§ **Custom logging** support for background jobs and events
16
15
 
17
16
  ## Installation
18
17
 
@@ -101,27 +100,35 @@ log_bench log/development.log
101
100
  - **Navigation**: `↑↓` or `jk` to navigate requests
102
101
  - **Pane switching**: `←→` or `hl` to switch between request list and details
103
102
  - **Filtering**: `f` to open filter dialog
103
+ - **Clear filter**: `c` to clear an active filter (press `escape` or `enter` before pressing `c` to clear)
104
104
  - **Sorting**: `s` to cycle through sort options (timestamp, duration, status)
105
105
  - **Auto-scroll**: `a` to toggle auto-scroll mode
106
- - **Clear**: `c` to clear current logs
107
106
  - **Quit**: `q` to exit
108
107
 
109
108
  ### Filtering
110
109
 
111
- Press `f` to open the filter dialog. You can filter by:
110
+ Press `f` to open the filter dialog.
111
+
112
+ In the left pane you can filter by:
112
113
 
113
114
  - **Method**: GET, POST, PUT, DELETE, etc.
114
115
  - **Path**: URL path patterns
115
116
  - **Status**: HTTP status codes (200, 404, 500, etc.)
116
117
  - **Controller**: Controller name
117
118
  - **Action**: Action name
118
- - **Duration**: Minimum request duration in ms
119
+ - **Request ID**: Unique request identifier
119
120
 
120
121
  Examples:
121
122
  - Filter by method: `GET`
122
123
  - Filter by path: `/api/users`
123
124
  - Filter by status: `500`
124
- - Filter by slow requests: duration `>100`
125
+ - Filter by controller: `UsersController`
126
+ - Filter by action: `create`
127
+ - Filter by request ID: `abcdef-b1n2mk ...`
128
+
129
+ In the right pane you can filter related log lines by text content to find specific SQL queries or anything else
130
+ you want to find in the logs.
131
+
125
132
 
126
133
  ## Log Format
127
134
 
data/exe/log_bench CHANGED
@@ -8,28 +8,19 @@ def show_help
8
8
  LogBench - Rails Log Viewer
9
9
 
10
10
  Usage:
11
- bundle exec log_bench [log_file]
12
- bundle exec log_bench --help
13
- bundle exec log_bench --version
11
+ log_bench [log_file]
12
+ log_bench --help
13
+ log_bench --version
14
14
 
15
15
  Examples:
16
- bundle exec log_bench # View log/development.log
17
- bundle exec log_bench log/production.log # View specific log file
18
- bundle exec log_bench /path/to/app/log/test.log # View log from another app
16
+ log_bench # View log/development.log
17
+ log_bench log/production.log # View specific log file
18
+ log_bench /path/to/app/log/test.log # View log from another app
19
19
 
20
20
  Setup (for Rails apps):
21
21
  See README.md for complete configuration instructions:
22
22
  https://github.com/silva96/log_bench#installation
23
23
 
24
- Custom Logging:
25
- # Create JSON loggers for background jobs, events, etc.
26
- logger = Logger.new('log/jobs.log')
27
- logger.formatter = LogBench::JsonFormatter.new
28
- logger.info({ message: "Job completed", job_id: 123 })
29
-
30
- # Then view with LogBench
31
- bundle exec log_bench log/jobs.log
32
-
33
24
  Requirements:
34
25
  - Lograge gem with JSON formatter
35
26
  - Rails application logs in lograge format
@@ -64,7 +55,7 @@ begin
64
55
  puts " 2. The log file exists and has content"
65
56
  puts " 3. Lograge is configured (see README.md for setup)"
66
57
  puts
67
- puts "For help: bundle exec log_bench --help"
58
+ puts "For help: log_bench --help"
68
59
  exit 1
69
60
  end
70
61
 
@@ -82,6 +73,6 @@ rescue => e
82
73
  puts " - Lograge not configured (see README.md for setup)"
83
74
  puts " - Log format not supported (LogBench requires lograge JSON format)"
84
75
  puts
85
- puts "For help: bundle exec log_bench --help"
76
+ puts "For help: log_bench --help"
86
77
  exit 1
87
78
  end
@@ -42,13 +42,7 @@ module LogBench
42
42
 
43
43
  def handle_filter_input(ch)
44
44
  case ch
45
- when 10, 13 # Enter - exit filter mode but keep filter text
46
- if state.filter_mode
47
- state.filter_mode = false
48
- elsif state.detail_filter_mode
49
- state.detail_filter_mode = false
50
- end
51
- when 27 # ESC - exit filter mode and clear filter
45
+ when 10, 13, 27
52
46
  state.exit_filter_mode
53
47
  when Curses::KEY_UP, "k", "K"
54
48
  state.exit_filter_mode
@@ -36,8 +36,6 @@ module LogBench
36
36
  add_new_requests(new_collection.requests)
37
37
  end
38
38
  rescue
39
- # Log error but continue monitoring
40
- # In a real app, you might want to handle this differently
41
39
  sleep 1
42
40
  end
43
41
  end
@@ -15,7 +15,6 @@ module LogBench
15
15
  end
16
16
 
17
17
  def parse_and_render(text, win)
18
- # Parse ANSI escape codes and render with proper colors
19
18
  parts = text.split(/(\e\[[0-9;]*m)/)
20
19
  current_color = nil
21
20
 
@@ -34,7 +33,6 @@ module LogBench
34
33
  end
35
34
 
36
35
  def wrap_ansi_text(text, max_width)
37
- # For ANSI text, we need to preserve color state across chunks
38
36
  clean_text = text.gsub(/\e\[[0-9;]*m/, "")
39
37
 
40
38
  if clean_text.length <= max_width
@@ -148,22 +148,10 @@ module LogBench
148
148
 
149
149
  # Add all related logs from the request
150
150
  request.related_logs.each do |log|
151
- content = case log
152
- when LogBench::Log::QueryEntry, LogBench::Log::CacheEntry, LogBench::Log::CallLineEntry
153
- log.content
154
- else
155
- log.raw_line # Fallback to raw line for other entry types
156
- end
157
-
158
- timing = case log
159
- when LogBench::Log::QueryEntry, LogBench::Log::CacheEntry
160
- log.timing
161
- end
162
-
163
151
  related << {
164
152
  type: log.type,
165
- content: content,
166
- timing: timing,
153
+ content: log.content,
154
+ timing: log.timing,
167
155
  timestamp: log.timestamp
168
156
  }
169
157
  end
@@ -75,7 +75,7 @@ module LogBench
75
75
  header_win.attron(A_DIM) do
76
76
  header_win.addstr("a:Auto-scroll(")
77
77
  header_win.attron(color_pair(3)) { header_win.addstr(state.auto_scroll ? "ON" : "OFF") }
78
- header_win.addstr(") | f:Filter | c:Clear | s:Sort(")
78
+ header_win.addstr(") | f:Filter | c:Clear filter | s:Sort(")
79
79
  header_win.attron(color_pair(3)) { header_win.addstr(state.sort.display_name) }
80
80
  header_win.addstr(") | q:Quit")
81
81
  end
@@ -100,20 +100,19 @@ module LogBench
100
100
  end
101
101
 
102
102
  def filtered_requests
103
- # First apply filter - match exactly like original logtail
104
103
  filtered = if main_filter.present?
105
104
  requests.select do |req|
106
105
  main_filter.matches?(req.path) ||
107
106
  main_filter.matches?(req.method) ||
108
107
  main_filter.matches?(req.controller) ||
109
108
  main_filter.matches?(req.action) ||
109
+ main_filter.matches?(req.status) ||
110
110
  main_filter.matches?(req.request_id)
111
111
  end
112
112
  else
113
113
  requests
114
114
  end
115
115
 
116
- # Then apply sorting using Sort domain object
117
116
  sort.sort_requests(filtered)
118
117
  end
119
118
 
@@ -3,14 +3,7 @@
3
3
  require "json"
4
4
 
5
5
  module LogBench
6
- # A simple JSON formatter for Rails loggers that creates LogBench-compatible entries
7
- # for non-request logging (background jobs, custom events, etc.)
8
- #
9
- # Usage:
10
- # logger = Logger.new(Rails.root.join('log', 'custom.log'))
11
- # logger.formatter = LogBench::JsonFormatter.new
12
- # logger.info("Background job completed", job_id: 123)
13
- #
6
+ # A simple JSON formatter for Rails loggers that creates LogBench-compatible
14
7
  class JsonFormatter < ::Logger::Formatter
15
8
  def call(severity, timestamp, progname, message)
16
9
  log_entry = build_log_entry(severity, timestamp, progname, message)
@@ -54,10 +47,8 @@ module LogBench
54
47
  end
55
48
 
56
49
  def lograge_message?(entry)
57
- # Check if the message field contains lograge JSON
58
50
  return false unless entry[:message].is_a?(String) && entry[:message].start_with?("{")
59
51
 
60
- # Try to parse and check for lograge fields
61
52
  begin
62
53
  parsed = JSON.parse(entry[:message])
63
54
  parsed.is_a?(Hash) && parsed["method"] && parsed["path"] && parsed["status"]
@@ -67,14 +58,12 @@ module LogBench
67
58
  end
68
59
 
69
60
  def parse_lograge_message(message_string)
70
- # Parse the lograge JSON string
71
61
  JSON.parse(message_string)
72
62
  rescue JSON::ParserError
73
63
  nil
74
64
  end
75
65
 
76
66
  def current_request_id
77
- # Try multiple ways to get the current request ID
78
67
  request_id = nil
79
68
 
80
69
  if defined?(Current) && Current.respond_to?(:request_id)
@@ -85,7 +74,6 @@ module LogBench
85
74
  request_id = Thread.current[:request_id]
86
75
  end
87
76
 
88
- # Return nil if no request ID found - let caller decide whether to generate UUID
89
77
  request_id
90
78
  end
91
79
  end
@@ -5,8 +5,6 @@ module LogBench
5
5
  class CacheEntry < Entry
6
6
  SQL_OPERATIONS = %w[SELECT INSERT UPDATE DELETE].freeze
7
7
 
8
- attr_reader :content, :timing
9
-
10
8
  def initialize(raw_line)
11
9
  super
12
10
  self.type = :cache
@@ -47,8 +45,7 @@ module LogBench
47
45
 
48
46
  private
49
47
 
50
- attr_reader :operation
51
- attr_writer :content, :timing, :operation
48
+ attr_writer :operation
52
49
 
53
50
  def extract_from_json(data)
54
51
  super
@@ -3,8 +3,6 @@
3
3
  module LogBench
4
4
  module Log
5
5
  class CallLineEntry < Entry
6
- attr_reader :content
7
-
8
6
  def initialize(raw_line)
9
7
  super
10
8
  self.type = :sql_call_line
@@ -30,7 +28,6 @@ module LogBench
30
28
 
31
29
  private
32
30
 
33
- attr_writer :content
34
31
  attr_accessor :file_path, :line_number, :method_name
35
32
 
36
33
  def extract_from_json(data)
@@ -3,7 +3,7 @@
3
3
  module LogBench
4
4
  module Log
5
5
  class Entry
6
- attr_reader :type, :raw_line, :request_id, :timestamp
6
+ attr_reader :type, :raw_line, :request_id, :timestamp, :content, :timing
7
7
 
8
8
  def initialize(raw_line)
9
9
  self.raw_line = raw_line.strip
@@ -42,7 +42,7 @@ module LogBench
42
42
 
43
43
  private
44
44
 
45
- attr_writer :type, :raw_line, :timestamp, :request_id
45
+ attr_writer :type, :raw_line, :timestamp, :request_id, :content, :timing
46
46
 
47
47
  def parse!
48
48
  parse_json
@@ -64,6 +64,7 @@ module LogBench
64
64
 
65
65
  self.timestamp = parse_timestamp(data["timestamp"])
66
66
  self.request_id = data["request_id"]
67
+ self.content = data["message"]
67
68
  self.type = determine_json_type(data)
68
69
  true
69
70
  end
@@ -14,8 +14,6 @@ module LogBench
14
14
  SAVEPOINT = "SAVEPOINT"
15
15
  SQL_OPERATIONS = [SELECT, INSERT, UPDATE, DELETE, TRANSACTION, BEGIN_TRANSACTION, COMMIT, ROLLBACK, SAVEPOINT].freeze
16
16
 
17
- attr_reader :content, :timing
18
-
19
17
  def initialize(raw_line)
20
18
  super
21
19
  self.type = :sql
@@ -125,8 +123,7 @@ module LogBench
125
123
 
126
124
  private
127
125
 
128
- attr_reader :operation
129
- attr_writer :content, :timing, :operation
126
+ attr_accessor :operation
130
127
  end
131
128
  end
132
129
  end
@@ -21,7 +21,7 @@ module LogBench
21
21
  Rails.application.config.lograge.enabled
22
22
  puts "βœ… LogBench is ready to use!"
23
23
  puts "=" * 70
24
- puts "View your logs: bundle exec log_bench log/development.log"
24
+ puts "View your logs: log_bench log/development.log"
25
25
  else
26
26
 
27
27
  puts "πŸš€ LogBench is ready to configure!"
@@ -31,10 +31,10 @@ module LogBench
31
31
  puts " 2. Configure lograge in config/environments/development.rb"
32
32
  puts " 3. Restart your Rails server"
33
33
  puts " 4. Make some requests to generate logs"
34
- puts " 5. View logs: bundle exec log_bench log/development.log"
34
+ puts " 5. View logs: log_bench log/development.log"
35
35
  puts
36
36
  end
37
- puts "For help: bundle exec log_bench --help"
37
+ puts "For help: log_bench --help"
38
38
  puts "=" * 70 + "\n"
39
39
  puts "=" * 70 + "\n"
40
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogBench
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -42,7 +42,7 @@ namespace :log_bench do
42
42
 
43
43
  puts
44
44
  puts "πŸŽ‰ LogBench is ready to use!"
45
- puts " Command: bundle exec log_bench #{log_file}"
45
+ puts " Command: log_bench #{log_file}"
46
46
  else
47
47
  puts "❌ Lograge is not enabled"
48
48
  puts
@@ -51,7 +51,7 @@ namespace :log_bench do
51
51
  puts " 2. Configure lograge in config/environments/development.rb"
52
52
  puts " 3. Restart your Rails server"
53
53
  puts " 4. Make some requests"
54
- puts " 5. Run: bundle exec log_bench log/development.log"
54
+ puts " 5. Run: log_bench log/development.log"
55
55
  end
56
56
  puts "=" * 60 + "\n"
57
57
  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.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - BenjamΓ­n Silva
@@ -148,8 +148,8 @@ metadata:
148
148
  documentation_uri: https://github.com/silva96/log_bench/blob/main/README.md
149
149
  post_install_message: "\n\U0001F389 LogBench installed successfully!\n\nNext steps:\n1.
150
150
  Configure Rails (see README.md for setup instructions)\n2. Restart your Rails server\n3.
151
- Make some requests to generate logs\n4. View logs: bundle exec log_bench log/development.log\n\nFor
152
- help: bundle exec log_bench --help\nDocumentation: https://github.com/silva96/log_bench\n\n"
151
+ Make some requests to generate logs\n4. View logs: log_bench log/development.log\n\nFor
152
+ help: log_bench --help\nDocumentation: https://github.com/silva96/log_bench\n\n"
153
153
  rdoc_options: []
154
154
  require_paths:
155
155
  - lib