betterlog 2.1.1 → 2.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: 5f2e9ee107c04ca121cd96cfa729d5f38ffa93ba4fcc72a0b98d9a6eff616177
4
- data.tar.gz: c921b345079562a1ea1959fbe357d86ee56a54922cb4d367d8b4c8bdff719d45
3
+ metadata.gz: e44f75b0aa17e54401d1ecb4ad6d33d8081cae0f6f07740a762d7597e06faa58
4
+ data.tar.gz: e76cd7fbdd63d2f881e3b8e370135466408161d352a81ff84b839cfa5c1ab41c
5
5
  SHA512:
6
- metadata.gz: 3e9527c09905b4263af1e541cc6b6c3c48f6712c50fa853b084ec07a29146da16aad4ebaed0d53d1fe6c0f95765d35a0fbdc970d78bd9b60ad105d7ca6c5ce11
7
- data.tar.gz: 2155967f4c360239bd4f45b33dfc7af976a9ef302caf1cd949a103167aeaf5d1d0a632c1411b99dfa254d5498ca53d732984fb656ae519df4bb0da1c21a12aaa
6
+ metadata.gz: 631e02be296ef311afa02fd8eb15bb6a2c9913c07ec175bd18c767c351b2431e0ec6eb5c01a7d8638b343b13d621b3790b3c710b5aad1bd728cb550e503c6266
7
+ data.tar.gz: 2ecc2726e28df7efe266cac59a2d6e39b376a1c3e84d2132ffb135cc83d65cf75f523cccea8f4b48587ee5a3c84dc19b18425e067bd2ad6ade239037c944c5d1
data/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-09-03 v2.1.3
4
+
5
+ - Improved documentation for the `colorize` method with detailed styling examples
6
+ - Enhanced documentation for the `format_pattern` method with a detailed syntax guide
7
+ - Added `doc` directory to `.gitignore` and updated `Rakefile` to include it in the ignore list
8
+
9
+ ## 2025-09-02 v2.1.2
10
+
11
+ - Moved only `filter_severities` method to private scope
12
+
3
13
  ## 2025-09-02 v2.1.1
4
14
 
5
15
  - Set required Ruby version to ~> **3.2** in both `Rakefile` and
data/Rakefile CHANGED
@@ -12,8 +12,8 @@ GemHadar do
12
12
  test_dir 'spec'
13
13
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
14
14
  '.ruby-version', '.AppleDouble', 'tags', '.DS_Store', '.utilsrc',
15
- '.bundle', '.byebug_history', 'errors.lst', '.yardoc', 'betterlog-server',
16
- 'gospace'
15
+ '.bundle', '.byebug_history', 'errors.lst', '.yardoc', 'doc',
16
+ 'betterlog-server', 'gospace'
17
17
  package_ignore '.all_images.yml', '.utilsrc', '.rspec', '.tool-versions',
18
18
  '.gitignore', *Dir['.semaphore/**/*'], *Dir['.github/**/*']
19
19
  readme 'README.md'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.3
data/betterlog.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 2.1.1 ruby lib
2
+ # stub: betterlog 2.1.3 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "2.1.1".freeze
6
+ s.version = "2.1.3".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]
data/bin/betterlog CHANGED
@@ -119,14 +119,13 @@ module Betterlog
119
119
  exit(0)
120
120
  end
121
121
 
122
- private\
123
122
  # Filters log severities based on command-line options.
124
123
  #
125
124
  # This method processes the configured severity filters from the options hash,
126
125
  # applying inclusive and exclusive selection criteria to narrow down the
127
126
  # available severity levels. It supports comparison operators for range-based
128
127
  # filtering and exact matches for specific severities.
129
- def filter_severities
128
+ private def filter_severities
130
129
  @severities = Log::Severity.all
131
130
  if severity = @opts[?S]
132
131
  severity.each do |s|
@@ -65,15 +65,48 @@ module Betterlog
65
65
  #
66
66
  # This method applies visual styling to a string by looking up the
67
67
  # appropriate style configuration based on the provided key and value,
68
- # then applying that style using the internal apply_style method.
69
- #
70
- # @param key [ Object ] the lookup key for determining the style
71
- # configuration
72
- # @param value [ Object ] the value used to determine which specific
73
- # style to apply
74
- # @param string [ Object ] the string to be colorized, defaults to the
75
- # key if not provided
76
- # @return [ String ] the colorized string based on the configured styles
68
+ # then applying that style using the internal apply_style method. The
69
+ # colorization logic supports both static and dynamic styling based on
70
+ # the value being formatted.
71
+ #
72
+ # <b>Style Configuration Patterns</b>
73
+ #
74
+ # Styles can be configured in several ways:
75
+ #
76
+ # <b>Static Styles</b>
77
+ # - String: Single ANSI color code (e.g., "red", "bold")
78
+ # - Array: Multiple ANSI codes (e.g., ["red", "bold"])
79
+ #
80
+ # <b>Dynamic Styles</b>
81
+ # - ComplexConfig::Settings: Different styles based on value content
82
+ # Example: { debug: "green", error: "red" } where the style is selected based on the value
83
+ #
84
+ # <b>Usage Examples</b>
85
+ #
86
+ # Given a configuration like:
87
+ # styles:
88
+ # 'timestamp': [ yellow, bold ]
89
+ # severity:
90
+ # debug: green
91
+ # info: green
92
+ # warn: yellow
93
+ # error: red
94
+ #
95
+ # The method will:
96
+ # - Colorize "{timestamp}" with yellow/bold styling
97
+ # - Colorize "{severity}" with green for "debug"/"info", yellow for "warn", red for "error"
98
+ #
99
+ # @param key [Object] the lookup key for determining the style configuration
100
+ # @param value [Object] the value used to determine which specific style to apply
101
+ # @param string [Object] the string to be colorized, defaults to the key if not provided
102
+ # @return [String] the colorized string based on the configured styles
103
+ # @see Betterlog::Log::EventFormatter#apply_style
104
+ #
105
+ # @example Static styling
106
+ # colorize(:timestamp, nil, "2023-12-01") # Returns colored timestamp string
107
+ #
108
+ # @example Dynamic styling based on value
109
+ # colorize(:severity, :error, "ERROR") # Returns red-colored string
77
110
  def colorize(key, value, string = key)
78
111
  case style = cc.log.styles[key]
79
112
  when nil, String, Array
@@ -109,18 +142,54 @@ module Betterlog
109
142
  end
110
143
  end
111
144
 
112
- # Formats a log event using a specified pattern with support for
113
- # directives and colorization.
145
+ # Formats a log event using a specified pattern with support for directives and colorization.
114
146
  #
115
- # This method processes a format string by replacing placeholders with
116
- # actual event data, applying formatting directives for special handling
117
- # of values like objects or timestamps, and optionally applying color
118
- # styling based on configured styles.
147
+ # This method processes a format string by replacing placeholders with actual event data,
148
+ # applying formatting directives for special handling of values like objects or timestamps,
149
+ # and optionally applying color styling based on configured styles.
119
150
  #
120
- # @param format [ String ] the format pattern to apply to the log event
121
- # @return [ String ] the formatted string representation of the log event
151
+ # <b>Format Pattern Syntax</b>
152
+ #
153
+ # Format patterns use curly braces `{}` to define placeholders with optional directives:
154
+ #
155
+ # <b>Basic Key Substitution</b>
156
+ # - `{key}` - Substitutes the value of `@event[key]`
157
+ # - `{-key}` - Invisible variant; omits output when value is nil (instead of showing `{key}`)
158
+ #
159
+ # <b>Object Formatting Directives</b>
160
+ # - `{%O%key}` - Formats complex objects (arrays/hashes) with nested structure visualization
161
+ # Example: Shows arrays with bullet points and hashes with key-value pairs
162
+ #
163
+ # <b>Timestamp Formatting Directives</b>
164
+ # - `{%t%key}` - Formats timestamp values with various time formats based on flag:
165
+ # - `%ut%key` - UTC ISO8601 format (e.g., "2023-12-01T10:30:45.123Z")
166
+ # - `%lt%key` - Local time ISO8601 format
167
+ # - `%it%key` - Unix timestamp integer (e.g., "1701423425")
168
+ # - `%ft%key` - Unix timestamp float (e.g., "1701423425.123")
169
+ # - `%t%key` (default) - UTC ISO8601 format
170
+ #
171
+ # <b>String Formatting Directives</b>
172
+ # - `{%.format%key}` - Applies Ruby string formatting using the `%` operator
173
+ # Example: `{%.2f%price}` formats a float to 2 decimal places
174
+ #
175
+ # <b>Colorization</b>
176
+ # Values are automatically colorized based on configured styles in the `styles` configuration.
177
+ # For example, timestamp values use yellow/bold styling, and severity levels use different colors
178
+ # based on their value (debug=green, warn=yellow, error=red, etc.).
179
+ #
180
+ # @param format [String] the format pattern to apply to the log event
181
+ # @return [String] the formatted string representation of the log event
122
182
  # @see Betterlog::Log::EventFormatter#format_object
123
183
  # @see Betterlog::Log::EventFormatter#colorize
184
+ #
185
+ # @example Basic usage with default configuration
186
+ # formatter.format_pattern(format: "{%lt%timestamp} {message}")
187
+ #
188
+ # @example Complex formatting with object display
189
+ # formatter.format_pattern(format: "{%O%backtrace} {message}")
190
+ #
191
+ # @example Conditional display of optional fields
192
+ # formatter.format_pattern(format: "{file}{-%O%backtrace}")
124
193
  def format_pattern(format:)
125
194
  format.
126
195
  gsub('\n', "\n").
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '2.1.1'
3
+ VERSION = '2.1.3'
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.1
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers