betterlog 2.1.2 → 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 +4 -4
- data/CHANGES.md +6 -0
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/betterlog.gemspec +2 -2
- data/lib/betterlog/log/event_formatter.rb +86 -17
- data/lib/betterlog/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e44f75b0aa17e54401d1ecb4ad6d33d8081cae0f6f07740a762d7597e06faa58
|
4
|
+
data.tar.gz: e76cd7fbdd63d2f881e3b8e370135466408161d352a81ff84b839cfa5c1ab41c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 631e02be296ef311afa02fd8eb15bb6a2c9913c07ec175bd18c767c351b2431e0ec6eb5c01a7d8638b343b13d621b3790b3c710b5aad1bd728cb550e503c6266
|
7
|
+
data.tar.gz: 2ecc2726e28df7efe266cac59a2d6e39b376a1c3e84d2132ffb135cc83d65cf75f523cccea8f4b48587ee5a3c84dc19b18425e067bd2ad6ade239037c944c5d1
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,11 @@
|
|
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
|
+
|
3
9
|
## 2025-09-02 v2.1.2
|
4
10
|
|
5
11
|
- Moved only `filter_severities` method to private scope
|
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', '
|
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
|
+
2.1.3
|
data/betterlog.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: betterlog 2.1.
|
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.
|
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]
|
@@ -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
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
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
|
-
#
|
117
|
-
#
|
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
|
-
#
|
121
|
-
#
|
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").
|
data/lib/betterlog/version.rb
CHANGED