betterlog 2.1.0 → 2.1.2

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: e5b1ea80565dc5b5e0b95a525f8e50a3aded59cd3038c2e76610d6fe36427d20
4
- data.tar.gz: 8b98f5b839d2bbaecb6bd2171a52e11c728a00eb415039d833669016b842fc2a
3
+ metadata.gz: 42be8d52810b7073915e4b1efea2bbf42a9dab3fce71392d2d76018a6e15f1b8
4
+ data.tar.gz: 614f43b1a12d2e45bd0149c32045bdba913269ffe3799958584ec2bcb2ad0007
5
5
  SHA512:
6
- metadata.gz: 5d9306aa22d8b0032d684d0e61026059aed39bf19ea2f83cef327d60b982f534eb70740e59e6610cc38223980cbab152ee9942e7c3b6af02418d1cec4bbc6182
7
- data.tar.gz: 372ab8b900747df79f51019b6905a66065b3c00157484da3aa3a5c963517e61411b2da7e443ae900d34af842d2d4f7fecccf09827b03adc947a9d57e5589a9af
6
+ metadata.gz: 88672071ddeea36aaca49a2f49ec2408f2e378b2f17de5c2aed437aeed1e73ba8e44ee0af0f9bac72c10f8561b226191e982f4d1076922cae54f1d91327ea846
7
+ data.tar.gz: 46686b79bf11b7013e784cd6b4031b686b3dedeab53f401fde392d852802e87ff01ee28014a125f601f4120263a6f3ce0c0d288995a3cf240dfa58d9c8310513
data/CHANGES.md ADDED
@@ -0,0 +1,342 @@
1
+ # Changes
2
+
3
+ ## 2025-09-02 v2.1.2
4
+
5
+ - Moved only `filter_severities` method to private scope
6
+
7
+ ## 2025-09-02 v2.1.1
8
+
9
+ - Set required Ruby version to ~> **3.2** in both `Rakefile` and
10
+ `betterlog.gemspec`
11
+ - Added `.all_images.yml`, `.tool-versions`, `.gitignore`, and files under
12
+ `.semaphore/` and `.github/` to package_ignore in `Rakefile`
13
+ - Added comprehensive documentation to the `Betterlog::App` class, including
14
+ detailed class documentation, method documentation with parameters and return
15
+ values, and improved code organization with comments
16
+ - Removed ruby version **3.1** from the image list in `.all_images.yml`
17
+ - Added `CHANGES.md` file to document project history and version updates
18
+
19
+ ## 2025-09-02 v2.1.0
20
+
21
+ - Improved documentation and added comprehensive comments throughout Betterlog
22
+ modules
23
+ - Updated Ruby version from **3.4.1** to **3.4.5** in tool versions
24
+ configuration
25
+ - Removed metric deprecation warning.
26
+
27
+ ## 2025-02-19 v2.0.6
28
+
29
+ - Added `licenses` attribute to GemHadar in Rakefile
30
+
31
+ ## 2025-02-13 v2.0.5
32
+
33
+ - Removed `gem update --system` command from Dockerfile to prevent version
34
+ changes
35
+ - Added `yaml-dev` package to `build-base` installation in Dockerfile
36
+ - Updated `gem install gem_hadar` command in Dockerfile to run without bundler
37
+ - Added support for Ruby versions **3.4** and **3.3** with new Docker image
38
+ configurations
39
+ - Updated `.tool-versions` file to use Ruby version **3.4.1** and removed
40
+ **2.3.17**
41
+
42
+ ## 2024-03-13 v2.0.4
43
+
44
+ - Improved the legacy event formatter implementation
45
+ - Updated code to use the new name for the legacy event formatter
46
+
47
+ ## 2024-03-13 v2.0.3
48
+
49
+ - Added global metadata support to the legacy emitter
50
+ - Renamed and moved the legacy formatter/emitter components
51
+ - Removed the passing of context to blocks in the code
52
+
53
+ ## 2024-01-25 v2.0.2
54
+
55
+ - Removed the passing of context to block in the codebase
56
+ - Eliminated unnecessary context parameter handling in block execution flow
57
+
58
+ ## 2023-08-17 v2.0.1
59
+
60
+ - Renamed `with_metadata` method to `with_meta`
61
+ - Added new `Betterlog.with_meth` convenience method
62
+ - Updated method names to improve clarity and consistency in logging
63
+ functionality
64
+
65
+ ## 2023-08-17 v2.0.0
66
+
67
+ - Removed obsolete metric support with warning implementation
68
+ - Simplified code significantly
69
+ - Added support for `Betterlog::GlobalMetadata` via block form of
70
+ `with_context` method
71
+ - Updated `with_context` method to handle context variable removal properly
72
+ - Changed behavior to warn about removed metric support instead of maintaining
73
+ it
74
+
75
+ ## 2023-08-16 v1.1.1
76
+
77
+ - Added Sidekiq context to metadata of regularly emitted events
78
+ - Enhanced event metadata with Sidekiq information for better tracking and
79
+ debugging capabilities
80
+
81
+ ## 2023-02-10 v1.1.0
82
+
83
+ - Added context of Sidekiq logger to legacy emitter output
84
+ - Enhanced logging capabilities by incorporating Sidekiq context information
85
+ - Improved debugging and monitoring of legacy emitter functionality
86
+ - Updated logging infrastructure to support Sidekiq integration
87
+ - Modified emitter output format to include additional contextual information
88
+
89
+ ## 2023-01-30 v1.0.0
90
+
91
+ - Removed the `log_pusher` functionality from the codebase
92
+ - Eliminated the associated logging mechanism that was previously used for
93
+ pushing logs
94
+
95
+ ## 2022-08-18 v0.20.3
96
+
97
+ - Added example code to demonstrate usage
98
+ - Updated build configuration to use Go version **1.17**
99
+ - Upgraded base image to Alpine **3.14.3**
100
+ - Removed deprecated `cloudbuild.yaml` file
101
+ - Implemented proper loading of version specification
102
+ - Configured CodeQL analysis workflow
103
+ - Reverted previous message-related changes
104
+ - Built project from scratch with updated dependencies
105
+ - Updated build system and tooling configurations
106
+
107
+ ## 2021-10-28 v0.20.2
108
+
109
+ - Reverted previous changes that modified the behavior of passing arguments
110
+ - Changed implementation to rely on the originally passed argument instead of
111
+ alternative approaches
112
+ - Removed modifications that had been previously introduced for argument
113
+ handling
114
+
115
+ ## 2021-10-28 v0.20.1
116
+
117
+ - Fixed backtrace parsing logic to handle edge cases properly
118
+ - Corrected backtrace parsing implementation for more reliable error reporting
119
+ - Improved backtrace parsing to work correctly with **Ruby** version **3.1**+
120
+ error messages
121
+ - Enhanced backtrace parsing to properly extract method names and file
122
+ locations from stack traces
123
+
124
+ ## 2021-10-26 v0.20.0
125
+
126
+ - Modified message coloring behavior to remove colors from JSON output
127
+ - Updated test execution to continue running tests even when push operations
128
+ fail
129
+
130
+ ## 2021-09-21 v0.19.0
131
+
132
+ - Upgraded Ruby version to **3.0.2**
133
+ - Upgraded labstack/echo to specific v4 version
134
+ - Upgraded Alpine Linux to version **3.14.2**
135
+ - Upgraded Alpine Linux to version **3.14.1**
136
+ - Upgraded Alpine Linux to version **3.14**
137
+ - Upgraded Alpine Linux to version **3.13.5**
138
+ - Upgraded Alpine Linux to version **3.13.4**
139
+ - Implemented git SHA tagging for master commits
140
+
141
+ ## 2021-03-05 v0.18.0
142
+
143
+ - Fixed compatibility issue with **Ruby 3.0**
144
+ - Updated version tag
145
+
146
+ ## 2021-03-01 v0.17.0
147
+
148
+ - Updated base image to **alpine 3.13.2**
149
+
150
+ ## 2021-02-10 v0.16.0
151
+
152
+ - Added check for tag name in the codebase
153
+ - Upgraded base system to Alpine version **3.13.1**
154
+
155
+ ## 2021-02-03 v0.15.2
156
+
157
+ - Handle invalid UTF-8 characters in log messages
158
+ - Add bx configuration
159
+ - Add path configuration
160
+ - Pass registry name being used
161
+ - Upgrade dependencies
162
+ - Base image on alpine:**3.12.3**
163
+ - Only push on master branch builds
164
+
165
+ ## 2020-12-07 v0.15.1
166
+
167
+ - Move testing configuration to Semaphore CI environment
168
+ - Improve search syntax implementation
169
+
170
+ ## 2020-11-02 v0.15.0
171
+
172
+ - Added test configuration for Semaphore CI platform
173
+ - Updated continuous integration setup to include Semaphore testing environment
174
+ - Configured build pipeline to run tests on Semaphore infrastructure
175
+ - Integrated Semaphore-specific test execution settings
176
+
177
+ ## 2020-08-26 v0.14.1
178
+
179
+ - Allow log file to be missing during loading process
180
+ - Handle cases where log file may not exist when loading configuration
181
+
182
+ ## 2020-07-30 v0.14.0
183
+
184
+ - Fixed regexp encoding match problem
185
+ - Made log level easily configurable
186
+
187
+ ## 2020-07-20 v0.13.1
188
+
189
+ - Replace existence check with boolean method
190
+ - Upgrade base image to Alpine **3.12.0**
191
+
192
+ ## 2020-05-12 v0.13.0
193
+
194
+ - Updated base image to **alpine 3.11.6**
195
+ - Modified `kubectl` config name in `betterlog_sink` to use `cluster.name` from
196
+ configuration instead of hardcoded value
197
+
198
+ ## 2020-04-20 v0.12.2
199
+
200
+ - Added support for using `as_json` method for automatic serialization
201
+ - Enabled automatic serialization functionality when `as_json` is present
202
+
203
+ ## 2020-04-02 v0.12.1
204
+
205
+ - Updated output handling to include **false** values in addition to previously
206
+ handled values
207
+ - Modified the output logic to ensure boolean **false** is properly processed
208
+ and displayed
209
+
210
+ ## 2020-04-02 v0.12.0
211
+
212
+ - Added ability to evaluate block results and log with metric
213
+ - Implemented new functionality for block result evaluation
214
+ - Enhanced logging capabilities with metric support
215
+ - Updated code to support metric-based logging of block evaluations
216
+ - Modified evaluation logic to incorporate metric tracking
217
+ - Added logging infrastructure for block result metrics
218
+ - Improved block evaluation reporting with metric integration
219
+
220
+ ## 2020-04-02 v0.11.0
221
+
222
+ - Simplified the interface by refactoring code structure
223
+ - Improved CLI command implementation for better usability
224
+ - Updated build configuration to target Alpine Linux version **3.11.5**
225
+ - Switched to using `better-builder` for enhanced build capabilities
226
+
227
+ ## 2020-01-22 v0.10.0
228
+
229
+ - Handle intermittent redis failover events with liberal logging to a fallback
230
+ logger
231
+ - Fallback to a standard stderr logger when redis has connection problems,
232
+ particularly during failover events
233
+ - Mute output and use expect instead for improved behavior
234
+ - Improve output formatting
235
+ - Add support for testing on Ruby **2.7**
236
+ - Include Redis failover fixes
237
+ - Add `cloudbuild.yaml` configuration file
238
+
239
+ ## 2020-01-17 v0.9.0
240
+
241
+ - Added support for using sentinel configuration for high availability Redis
242
+ setups
243
+ - Included `error_class` in the pl (package list) command output format
244
+
245
+ ## 2019-11-15 v0.8.1
246
+
247
+ - Fixed the output format of metrics in the `Metric` class
248
+ - Repurposed the `type` attribute to function as a metric identifier across all
249
+ metrics
250
+ - Updated metric handling to use `metric` as the primary classification instead
251
+ of `type`
252
+
253
+ ## 2019-11-15 v0.8.0
254
+
255
+ - Changed the keyword arguments and semantics of the `Log.metric` method
256
+ - Updated the `Log.metric` method to support new parameter handling
257
+ - Modified how metric data is processed and stored within the logging system
258
+ - Adjusted internal logic for metric collection and reporting
259
+ - Enhanced flexibility in how metrics are configured and used throughout the
260
+ application
261
+
262
+ ## 2019-11-06 v0.7.2
263
+
264
+ - Prevented honeybadger notifier from modifying its argument, which caused
265
+ circular reference issues
266
+ - Removed original hash from being passed to honeybadger as it corrupts the
267
+ data structure
268
+ - Fixed circular reference problem in honeybadger integration by avoiding
269
+ modification of notifier arguments
270
+ - Ensured honeybadger does not ruin the original hash by not passing it through
271
+ - Addressed issue where honeybadger was modifying its input argument causing
272
+ unexpected behavior
273
+
274
+ ## 2019-11-01 v0.7.1
275
+
276
+ - Fixed casing issues in the codebase
277
+ - Updated version number to **1.5.0**
278
+
279
+ ## 2019-10-31 v0.7.0
280
+
281
+ - Allow configuration using `redis_url` directly by catching
282
+ `Redis::CannotConnectError` to prevent application crashes and disable
283
+ logging instead
284
+ - Implement flyweight pattern on `Betterlog::Log::Severity` constant wrapper
285
+ for improved performance
286
+ - Add test for circular regression with repeated immediate objects
287
+ - Use `tins symbolize_keys_recursive` to handle circular data structures
288
+ - Fix clobbering of repeated scalar values in configuration
289
+ - Switch to using `go mod` for package management
290
+ - Add server and clients for logging functionality
291
+
292
+ ## 2019-07-22 v0.6.1
293
+
294
+ - Made `maximum buffer_size` configurable through a new configuration option
295
+ - Added ability to customize the buffer size limit for data processing
296
+ operations
297
+
298
+ ## 2019-07-18 v0.6.0
299
+
300
+ - Updated implementation to actually perform the actions previously only
301
+ announced
302
+ - Fixed discrepancy between declared functionality and actual code behavior
303
+ - Ensured proper execution of intended operations in the codebase
304
+
305
+ ## 2019-07-18 v0.5.0
306
+
307
+ - Fixed implementation to actually perform the intended behavior as announced
308
+ in previous commit
309
+ - Corrected logic to properly handle the expected functionality for **v3.5.0**
310
+ release
311
+
312
+ ## 2019-07-17 v0.4.0
313
+
314
+ - Added lock mechanism to `betterlog_pusher` to ensure the task runs only once,
315
+ preventing issues during scalingo deployments where the task might start
316
+ multiple times simultaneously
317
+ - Improved test specifications
318
+ - Added configuration hints for better user guidance
319
+ - Updated example `log.yml` configuration file
320
+ - Enhanced documentation with additional information
321
+
322
+ ## 2019-07-15 v0.3.0
323
+
324
+ - Added `betterlog_sink` command and sink to path
325
+ - Updated dependency to use the newest version of `gem_hadar` **1.0.0**
326
+
327
+ ## 2019-07-04 v0.2.2
328
+
329
+ - Added support for providing health page in disabled SSL mode
330
+ - Moved some code into separate files to improve organization
331
+ - Bumped version number to **0.15.0**
332
+
333
+ ## 2019-06-27 v0.2.1
334
+
335
+ - Logger configuration still requires manual setup
336
+ - The `Logger` component needs explicit configuration rather than automatic
337
+ initialization
338
+ - Users must manually configure the logger settings in their applications
339
+
340
+ ## 2019-06-27 v0.2.0
341
+
342
+ * Start
data/Rakefile CHANGED
@@ -14,11 +14,15 @@ GemHadar do
14
14
  '.ruby-version', '.AppleDouble', 'tags', '.DS_Store', '.utilsrc',
15
15
  '.bundle', '.byebug_history', 'errors.lst', '.yardoc', 'betterlog-server',
16
16
  'gospace'
17
+ package_ignore '.all_images.yml', '.utilsrc', '.rspec', '.tool-versions',
18
+ '.gitignore', *Dir['.semaphore/**/*'], *Dir['.github/**/*']
17
19
  readme 'README.md'
18
20
  title "#{name.camelize}"
19
21
  executables %w[ betterlog ]
20
22
  licenses << 'Apache-2.0'
21
23
 
24
+ required_ruby_version '~> 3.2'
25
+
22
26
  dependency 'tins', '~>1.3', '>=1.22.0'
23
27
  dependency 'complex_config'
24
28
  dependency 'file-tail', '~>1.0'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.1.2
data/betterlog.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 2.1.0 ruby lib
2
+ # stub: betterlog 2.1.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "2.1.0".freeze
6
+ s.version = "2.1.2".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
13
13
  s.email = "developers@betterplace.org".freeze
14
14
  s.executables = ["betterlog".freeze]
15
15
  s.extra_rdoc_files = ["README.md".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/legacy_event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze]
16
- s.files = [".all_images.yml".freeze, ".github/workflows/codeql-analysis.yml".freeze, ".gitignore".freeze, ".semaphore/semaphore.yml".freeze, ".tool-versions".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "bin/betterlog".freeze, "config/log.yml".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/legacy_event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/legacy_event_formatter_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/version_spec.rb".freeze, "spec/spec_helper.rb".freeze]
16
+ s.files = ["CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "bin/betterlog".freeze, "config/log.yml".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/legacy_event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/legacy_event_formatter_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/version_spec.rb".freeze, "spec/spec_helper.rb".freeze]
17
17
  s.homepage = "http://github.com/betterplace/betterlog".freeze
18
18
  s.licenses = ["Apache-2.0".freeze]
19
19
  s.rdoc_options = ["--title".freeze, "Betterlog".freeze, "--main".freeze, "README.md".freeze]
20
+ s.required_ruby_version = Gem::Requirement.new("~> 3.2".freeze)
20
21
  s.rubygems_version = "3.6.9".freeze
21
22
  s.summary = "Structured logging support for bp".freeze
22
23
  s.test_files = ["spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/legacy_event_formatter_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/version_spec.rb".freeze, "spec/spec_helper.rb".freeze]
data/bin/betterlog CHANGED
@@ -7,7 +7,43 @@ require 'zlib'
7
7
  require 'file/tail'
8
8
 
9
9
  module Betterlog
10
+ # The main application class responsible for processing command-line arguments,
11
+ # configuring log filtering and formatting options, and orchestrating the core
12
+ # log processing workflow.
13
+ #
14
+ # This class serves as the entry point for the betterlog CLI tool. It handles
15
+ # argument parsing, configuration of filters (severity, search terms, emitters),
16
+ # and manages the different modes of operation including file following,
17
+ # stdin filtering, and file-based processing.
18
+ #
19
+ # The application supports various features such as:
20
+ # - Real-time log file monitoring with -f flag
21
+ # - Severity-based filtering with -S flag
22
+ # - Search term matching with -s flag
23
+ # - Configuration file shortcuts with -F flag
24
+ # - Pretty-printing with color support via -p and -c flags
25
+ # - Support for gzipped log files
26
+ # - Multiple log source handling
27
+ #
28
+ # Example usage:
29
+ # # Follow Rails logs in long format with colors for errors or greater
30
+ # $ betterlog -f -F rails -p long -c -S ">=error"
31
+ #
32
+ # # Match any event containing SELECT
33
+ # $ betterlog -f -s SELECT
34
+ #
35
+ # # Follow multiple log files with default format in colors
36
+ # $ betterlog -f -F rails -F redis -pd -c -n 10
10
37
  class App
38
+ # Initializes a new instance with command-line arguments.
39
+ #
40
+ # This constructor sets up the object by processing command-line arguments,
41
+ # configuring options for filtering and formatting, and preparing the
42
+ # internal state for log processing operations.
43
+ #
44
+ # @param args [ Array<String> ] an array of command-line arguments to be
45
+ # processed @return [ Betterlog::CLI ] returns the initialized instance
46
+ # itself
11
47
  def initialize(args = ARGV.dup)
12
48
  STDOUT.sync = true
13
49
  @args = args
@@ -16,8 +52,17 @@ module Betterlog
16
52
  @opts[?h] and usage
17
53
  end
18
54
 
55
+ # Displays the usage information and help text for the betterlog command.
56
+ #
57
+ # This method outputs a formatted help message that describes the available
58
+ # command-line options, format specifiers, severity levels, and configuration
59
+ # file shortcuts for the betterlog tool. It provides examples of common usage
60
+ # patterns and then exits the program with a success status.
61
+ #
62
+ # @see Betterlog::Log::Severity#all
63
+ # @see ComplexConfig::Settings#attribute_names
19
64
  def usage
20
- puts <<~end
65
+ puts <<~EOT
21
66
  Usage: #{prog} [OPTIONS] [LOGFILES]
22
67
 
23
68
  Options are
@@ -70,12 +115,17 @@ module Betterlog
70
115
 
71
116
  $ betterlog -n 10 unicorn.log
72
117
 
73
- end
118
+ EOT
74
119
  exit(0)
75
120
  end
76
121
 
77
- private\
78
- def filter_severities
122
+ # Filters log severities based on command-line options.
123
+ #
124
+ # This method processes the configured severity filters from the options hash,
125
+ # applying inclusive and exclusive selection criteria to narrow down the
126
+ # available severity levels. It supports comparison operators for range-based
127
+ # filtering and exact matches for specific severities.
128
+ private def filter_severities
79
129
  @severities = Log::Severity.all
80
130
  if severity = @opts[?S]
81
131
  severity.each do |s|
@@ -90,14 +140,37 @@ module Betterlog
90
140
  end
91
141
  end
92
142
 
143
+ # Returns the base name of the current program file.
144
+ #
145
+ # This method extracts and returns the file name portion of the script
146
+ # being executed, excluding any directory path components.
147
+ #
148
+ # @return [ String ] the base name of the current program file
93
149
  def prog
94
150
  File.basename($0)
95
151
  end
96
152
 
153
+ # Returns the emitters option value as an array.
154
+ #
155
+ # This method retrieves the emitters option from the internal options hash
156
+ # and ensures it is returned as an array format, even if it was originally
157
+ # provided as a single value.
158
+ #
159
+ # @return [ Array ] the array of emitters, or an empty array if none were
160
+ # specified
97
161
  def emitters
98
162
  Array(@opts[?e])
99
163
  end
100
164
 
165
+ # Checks if a log event matches the specified search criteria.
166
+ #
167
+ # This method evaluates whether a given log event satisfies the search
168
+ # parameters defined in the instance options. It supports searching within
169
+ # nested hash values and direct string matching against the JSON
170
+ # representation of the event.
171
+ #
172
+ # @param event [ Betterlog::Log::Event ] the log event to be checked against the search criteria
173
+ # @return [ TrueClass, FalseClass ] true if the event matches all search criteria, false otherwise
101
174
  def search_matched?(event)
102
175
  return true unless @opts[?s]
103
176
  @opts[?s].all? do |param|
@@ -114,6 +187,15 @@ module Betterlog
114
187
  end
115
188
  end
116
189
 
190
+ # Outputs a formatted log event to the console based on configured options and filters.
191
+ #
192
+ # This method processes a log event by checking if it matches the configured severity
193
+ # levels, emitters, and search criteria. If the event passes all filters, it formats
194
+ # the event according to the specified output options and prints it to standard output.
195
+ # The formatting can be JSON, a custom format, or a simple string representation.
196
+ #
197
+ # @param prefix [ String ] A string to prepend to the formatted event output
198
+ # @param event [ Betterlog::Log::Event ] The log event to be processed and displayed
117
199
  def output_log_event(prefix, event)
118
200
  return unless @severities.include?(event.severity)
119
201
  return if emitters.full? && !emitters.include?(event.emitter)
@@ -128,6 +210,17 @@ module Betterlog
128
210
  end
129
211
  end
130
212
 
213
+ # Parses a log line and outputs it as a structured event or plain text.
214
+ #
215
+ # This method processes a log line by attempting to parse it as a
216
+ # structured log event. If parsing succeeds, the event is formatted and
217
+ # displayed with an optional filename prefix. If the line doesn't match the
218
+ # expected structured format but appears to have an ISO timestamp prefix,
219
+ # it creates a new event from that data. Otherwise, the raw line is output
220
+ # as-is unless error handling is enabled.
221
+ #
222
+ # @param l [ String ] the log line to process
223
+ # @param filename [ String, nil ] the name of the file the log line came from
131
224
  def output_log_line(l, filename)
132
225
  l.blank? and return
133
226
  prefix =
@@ -152,6 +245,16 @@ module Betterlog
152
245
  @opts[?e] or puts "#{prefix}#{l}"
153
246
  end
154
247
 
248
+ # Processes configuration file arguments based on command-line options and
249
+ # configuration settings.
250
+ #
251
+ # This method handles the logic for resolving and expanding configuration
252
+ # file references provided via the -F command-line flag or falling back to
253
+ # default Rails configuration files. It ensures that the resulting argument
254
+ # list contains unique filenames after processing.
255
+ #
256
+ # @param args [ Array<String> ] The array of arguments to be processed
257
+ # @return [ Array<String> ] The processed and deduplicated array of filenames
155
258
  def query_config_file_configuration
156
259
  if @opts[?F]
157
260
  if cfs = cc.log.config_files?
@@ -172,6 +275,16 @@ module Betterlog
172
275
  @args.uniq!
173
276
  end
174
277
 
278
+ # Follows log files and outputs their contents in real-time.
279
+ #
280
+ # This method sets up a file tailing mechanism to monitor specified log
281
+ # files for new content. It creates a group of files to tail, configures
282
+ # the polling interval, and starts a background thread to process new lines
283
+ # as they are written to the files. The method handles cases where files do
284
+ # not exist by outputting a warning message and skipping those files.
285
+ #
286
+ # @see File::Tail::Group
287
+ # @see File::Tail::File
175
288
  def follow_files
176
289
  group = File::Tail::Group.new
177
290
  @args.each do |f|
@@ -189,6 +302,16 @@ module Betterlog
189
302
  rescue Interrupt
190
303
  end
191
304
 
305
+ # Filters log files from command line arguments, processing each file line
306
+ # by line.
307
+ #
308
+ # This method iterates over the provided file paths, checking their
309
+ # existence and processing them accordingly. For gzipped files, it uses
310
+ # Zlib::GzipReader to decompress and read the content. For regular files,
311
+ # it uses File::Tail::Logfile to read the lines. Each line is then passed
312
+ # to the output_log_line method for further processing.
313
+ #
314
+ # @param args [ Array<String> ] An array of file paths to be processed
192
315
  def filter_argv
193
316
  for fn in @args
194
317
  unless File.exist?(fn)
@@ -212,12 +335,25 @@ module Betterlog
212
335
  end
213
336
  end
214
337
 
338
+ # Processes each line from standard input and outputs formatted log lines.
339
+ #
340
+ # This method reads all lines from STDIN and passes each line to the
341
+ # output_log_line method for processing and formatting. It is typically
342
+ # used to filter or transform log data coming from stdin before outputting
343
+ # it.
344
+ #
345
+ # @param _ [ nil ] This method does not require any parameters
215
346
  def filter_stdin
216
347
  STDIN.each_line do |l|
217
348
  output_log_line(l, nil)
218
349
  end
219
350
  end
220
351
 
352
+ # Outputs log source information to standard error.
353
+ #
354
+ # This method prints information about the log sources being tracked to
355
+ # standard error, including whether stdin or specific files are being
356
+ # monitored, along with the configured severity levels.
221
357
  def output_log_sources
222
358
  if @args.empty?
223
359
  STDERR.puts "#{prog} tracking stdin\nseverities: #{@severities * ?|}"
@@ -228,6 +364,14 @@ module Betterlog
228
364
  end
229
365
  end
230
366
 
367
+ # Runs the main application logic based on command-line options and
368
+ # arguments.
369
+ #
370
+ # This method orchestrates the core functionality of the application by
371
+ # determining the appropriate logging behavior based on the provided
372
+ # command-line flags and input sources. It handles file following,
373
+ # filtering from standard input, or filtering from command-line arguments
374
+ # depending on the configuration.
231
375
  def run
232
376
  if @opts[?f]
233
377
  query_config_file_configuration
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '2.1.0'
3
+ VERSION = '2.1.2'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers
@@ -215,11 +215,7 @@ extra_rdoc_files:
215
215
  - lib/betterlog/railtie.rb
216
216
  - lib/betterlog/version.rb
217
217
  files:
218
- - ".all_images.yml"
219
- - ".github/workflows/codeql-analysis.yml"
220
- - ".gitignore"
221
- - ".semaphore/semaphore.yml"
222
- - ".tool-versions"
218
+ - CHANGES.md
223
219
  - Gemfile
224
220
  - LICENSE
225
221
  - README.md
@@ -258,9 +254,9 @@ require_paths:
258
254
  - lib
259
255
  required_ruby_version: !ruby/object:Gem::Requirement
260
256
  requirements:
261
- - - ">="
257
+ - - "~>"
262
258
  - !ruby/object:Gem::Version
263
- version: '0'
259
+ version: '3.2'
264
260
  required_rubygems_version: !ruby/object:Gem::Requirement
265
261
  requirements:
266
262
  - - ">="
data/.all_images.yml DELETED
@@ -1,18 +0,0 @@
1
- dockerfile: |-
2
- RUN apk add --no-cache yaml-dev build-base git
3
- RUN gem install gem_hadar
4
-
5
- script: &script |-
6
- echo -e "\e[1m"
7
- ruby -v
8
- echo -e "\e[0m"
9
- bundle
10
- rake spec
11
-
12
- fail_fast: yes
13
-
14
- images:
15
- ruby:3.4-alpine: *script
16
- ruby:3.3-alpine: *script
17
- ruby:3.2-alpine: *script
18
- ruby:3.1-alpine: *script
@@ -1,72 +0,0 @@
1
- # For most projects, this workflow file will not need changing; you simply need
2
- # to commit it to your repository.
3
- #
4
- # You may wish to alter this file to override the set of languages analyzed,
5
- # or to provide custom queries or build logic.
6
- #
7
- # ******** NOTE ********
8
- # We have attempted to detect the languages in your repository. Please check
9
- # the `language` matrix defined below to confirm you have the correct set of
10
- # supported CodeQL languages.
11
- #
12
- name: "CodeQL"
13
-
14
- on:
15
- push:
16
- branches: [ master ]
17
- pull_request:
18
- # The branches below must be a subset of the branches above
19
- branches: [ master ]
20
- schedule:
21
- - cron: '27 21 * * 1'
22
-
23
- jobs:
24
- analyze:
25
- name: Analyze
26
- runs-on: ubuntu-latest
27
- permissions:
28
- actions: read
29
- contents: read
30
- security-events: write
31
-
32
- strategy:
33
- fail-fast: false
34
- matrix:
35
- language: [ 'go', 'ruby' ]
36
- # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
- # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38
-
39
- steps:
40
- - name: Checkout repository
41
- uses: actions/checkout@v3
42
-
43
- # Initializes the CodeQL tools for scanning.
44
- - name: Initialize CodeQL
45
- uses: github/codeql-action/init@v2
46
- with:
47
- languages: ${{ matrix.language }}
48
- # If you wish to specify custom queries, you can do so here or in a config file.
49
- # By default, queries listed here will override any specified in a config file.
50
- # Prefix the list here with "+" to use these queries and those in the config file.
51
-
52
- # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53
- # queries: security-extended,security-and-quality
54
-
55
-
56
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57
- # If this step fails, then you should remove it and run the build manually (see below)
58
- - name: Autobuild
59
- uses: github/codeql-action/autobuild@v2
60
-
61
- # ℹ️ Command-line programs to run using the OS shell.
62
- # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63
-
64
- # If the Autobuild fails above, remove it and uncomment the following three lines.
65
- # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66
-
67
- # - run: |
68
- # echo "Run, Build Application using script"
69
- # ./location_of_script_within_repo/buildscript.sh
70
-
71
- - name: Perform CodeQL Analysis
72
- uses: github/codeql-action/analyze@v2
data/.gitignore DELETED
@@ -1,16 +0,0 @@
1
- .*.sw[pon]
2
- .AppleDouble
3
- .DS_Store
4
- .bundle
5
- .byebug_history
6
- .ruby-version
7
- .rvmrc
8
- .utilsrc
9
- .yardoc
10
- Gemfile.lock
11
- betterlog-server
12
- coverage
13
- errors.lst
14
- gospace
15
- pkg
16
- tags
@@ -1,45 +0,0 @@
1
- version: v1.0
2
- name: Betterlog pipeline
3
- agent:
4
- machine:
5
- type: e1-standard-2
6
- os_image: ubuntu2004
7
-
8
- blocks:
9
- - name: Caching
10
- task:
11
- prologue:
12
- commands:
13
- - checkout
14
- jobs:
15
- - name: cache bundle
16
- commands:
17
- - sem-version ruby $(awk '/^ruby/ { print $2 }' .tool-versions)
18
- - cache restore gems-$SEMAPHORE_GIT_BRANCH,gems-master
19
- - bundle config set path 'vendor/bundle'
20
- - bundle config jobs $(getconf _NPROCESSORS_ONLN)
21
- - bundle install
22
- - cache store gems-$SEMAPHORE_GIT_BRANCH vendor/bundle
23
-
24
- - name: "Unit tests"
25
- task:
26
- env_vars:
27
- - name: RAILS_ENV
28
- value: test
29
- prologue:
30
- commands:
31
- - checkout
32
-
33
- # Setup ruby
34
- - sem-version ruby $(awk '/^ruby/ { print $2 }' .tool-versions)
35
-
36
- # Setup gems
37
- - cache restore gems-$SEMAPHORE_GIT_BRANCH,gems-master
38
- - bundle config set path 'vendor/bundle'
39
- - bundle config jobs $(getconf _NPROCESSORS_ONLN)
40
- - bundle install
41
-
42
- jobs:
43
- - name: RSpec Unit Tests
44
- commands:
45
- - bundle exec rake
data/.tool-versions DELETED
@@ -1 +0,0 @@
1
- ruby 3.4.5