makit 0.0.140 → 0.0.141
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/README.md +41 -41
- data/exe/makit +5 -5
- data/lib/makit/apache.rb +28 -28
- data/lib/makit/auto.rb +48 -48
- data/lib/makit/cli/build_commands.rb +500 -500
- data/lib/makit/cli/generators/base_generator.rb +74 -74
- data/lib/makit/cli/generators/dotnet_generator.rb +50 -50
- data/lib/makit/cli/generators/generator_factory.rb +49 -49
- data/lib/makit/cli/generators/node_generator.rb +50 -50
- data/lib/makit/cli/generators/ruby_generator.rb +77 -77
- data/lib/makit/cli/generators/rust_generator.rb +50 -50
- data/lib/makit/cli/generators/templates/dotnet_templates.rb +167 -167
- data/lib/makit/cli/generators/templates/node_templates.rb +161 -161
- data/lib/makit/cli/generators/templates/ruby/gemfile.rb +26 -26
- data/lib/makit/cli/generators/templates/ruby/gemspec.rb +40 -40
- data/lib/makit/cli/generators/templates/ruby/main_lib.rb +33 -33
- data/lib/makit/cli/generators/templates/ruby/rakefile.rb +35 -35
- data/lib/makit/cli/generators/templates/ruby/readme.rb +63 -63
- data/lib/makit/cli/generators/templates/ruby/test.rb +39 -39
- data/lib/makit/cli/generators/templates/ruby/test_helper.rb +29 -29
- data/lib/makit/cli/generators/templates/ruby/version.rb +29 -29
- data/lib/makit/cli/generators/templates/rust_templates.rb +128 -128
- data/lib/makit/cli/main.rb +69 -69
- data/lib/makit/cli/project_commands.rb +868 -868
- data/lib/makit/cli/repository_commands.rb +661 -661
- data/lib/makit/cli/strategy_commands.rb +203 -203
- data/lib/makit/cli/utility_commands.rb +521 -521
- data/lib/makit/commands/factory.rb +359 -359
- data/lib/makit/commands/middleware/base.rb +73 -73
- data/lib/makit/commands/middleware/cache.rb +248 -248
- data/lib/makit/commands/middleware/command_logger.rb +312 -312
- data/lib/makit/commands/middleware/validator.rb +269 -269
- data/lib/makit/commands/request.rb +316 -316
- data/lib/makit/commands/result.rb +323 -323
- data/lib/makit/commands/runner.rb +388 -385
- data/lib/makit/commands/strategies/base.rb +171 -171
- data/lib/makit/commands/strategies/child_process.rb +165 -165
- data/lib/makit/commands/strategies/factory.rb +136 -136
- data/lib/makit/commands/strategies/synchronous.rb +139 -139
- data/lib/makit/commands.rb +50 -50
- data/lib/makit/configuration/dotnet_project.rb +12 -12
- data/lib/makit/configuration/gitlab_helper.rb +58 -58
- data/lib/makit/configuration/project.rb +168 -168
- data/lib/makit/configuration/rakefile_helper.rb +43 -43
- data/lib/makit/configuration/step.rb +34 -34
- data/lib/makit/configuration/timeout.rb +74 -74
- data/lib/makit/configuration.rb +15 -15
- data/lib/makit/content/default_gitignore.rb +7 -7
- data/lib/makit/content/default_gitignore.txt +225 -225
- data/lib/makit/content/default_rakefile.rb +13 -13
- data/lib/makit/content/gem_rakefile.rb +16 -16
- data/lib/makit/context.rb +1 -1
- data/lib/makit/data.rb +49 -49
- data/lib/makit/directories.rb +140 -140
- data/lib/makit/directory.rb +262 -262
- data/lib/makit/docs/files.rb +89 -89
- data/lib/makit/docs/rake.rb +102 -102
- data/lib/makit/dotnet/cli.rb +69 -69
- data/lib/makit/dotnet/project.rb +217 -217
- data/lib/makit/dotnet/solution.rb +38 -38
- data/lib/makit/dotnet/solution_classlib.rb +239 -239
- data/lib/makit/dotnet/solution_console.rb +264 -264
- data/lib/makit/dotnet/solution_maui.rb +354 -354
- data/lib/makit/dotnet/solution_wasm.rb +275 -275
- data/lib/makit/dotnet/solution_wpf.rb +304 -304
- data/lib/makit/dotnet.rb +102 -102
- data/lib/makit/email.rb +90 -90
- data/lib/makit/environment.rb +142 -142
- data/lib/makit/examples/runner.rb +370 -370
- data/lib/makit/exceptions.rb +45 -45
- data/lib/makit/fileinfo.rb +24 -24
- data/lib/makit/files.rb +43 -43
- data/lib/makit/gems.rb +40 -40
- data/lib/makit/git/cli.rb +54 -54
- data/lib/makit/git/repository.rb +90 -90
- data/lib/makit/git.rb +98 -98
- data/lib/makit/gitlab_runner.rb +59 -59
- data/lib/makit/humanize.rb +137 -137
- data/lib/makit/indexer.rb +47 -47
- data/lib/makit/logging/configuration.rb +308 -308
- data/lib/makit/logging/format_registry.rb +84 -84
- data/lib/makit/logging/formatters/base.rb +39 -39
- data/lib/makit/logging/formatters/console_formatter.rb +140 -140
- data/lib/makit/logging/formatters/json_formatter.rb +65 -65
- data/lib/makit/logging/formatters/plain_text_formatter.rb +71 -71
- data/lib/makit/logging/formatters/text_formatter.rb +64 -64
- data/lib/makit/logging/log_request.rb +119 -119
- data/lib/makit/logging/logger.rb +199 -199
- data/lib/makit/logging/sinks/base.rb +91 -91
- data/lib/makit/logging/sinks/console.rb +72 -72
- data/lib/makit/logging/sinks/file_sink.rb +92 -92
- data/lib/makit/logging/sinks/structured.rb +123 -123
- data/lib/makit/logging/sinks/unified_file_sink.rb +296 -296
- data/lib/makit/logging.rb +565 -565
- data/lib/makit/markdown.rb +75 -75
- data/lib/makit/mp/basic_object_mp.rb +17 -17
- data/lib/makit/mp/command_mp.rb +13 -13
- data/lib/makit/mp/command_request.mp.rb +17 -17
- data/lib/makit/mp/project_mp.rb +199 -199
- data/lib/makit/mp/string_mp.rb +199 -191
- data/lib/makit/nuget.rb +74 -74
- data/lib/makit/port.rb +32 -32
- data/lib/makit/process.rb +163 -163
- data/lib/makit/protoc.rb +107 -107
- data/lib/makit/rake/cli.rb +196 -196
- data/lib/makit/rake/trace_controller.rb +173 -173
- data/lib/makit/rake.rb +80 -80
- data/lib/makit/ruby/cli.rb +185 -185
- data/lib/makit/ruby.rb +25 -25
- data/lib/makit/secrets.rb +51 -51
- data/lib/makit/serializer.rb +130 -130
- data/lib/makit/services/builder.rb +186 -186
- data/lib/makit/services/error_handler.rb +226 -226
- data/lib/makit/services/repository_manager.rb +231 -231
- data/lib/makit/services/validator.rb +112 -112
- data/lib/makit/setup/classlib.rb +101 -101
- data/lib/makit/setup/gem.rb +268 -268
- data/lib/makit/setup/razorclasslib.rb +101 -101
- data/lib/makit/setup/runner.rb +54 -54
- data/lib/makit/setup.rb +5 -5
- data/lib/makit/show.rb +110 -110
- data/lib/makit/storage.rb +126 -126
- data/lib/makit/symbols.rb +170 -170
- data/lib/makit/task_info.rb +130 -130
- data/lib/makit/tasks/at_exit.rb +15 -15
- data/lib/makit/tasks/build.rb +22 -22
- data/lib/makit/tasks/clean.rb +13 -13
- data/lib/makit/tasks/configure.rb +10 -10
- data/lib/makit/tasks/format.rb +10 -10
- data/lib/makit/tasks/hook_manager.rb +443 -443
- data/lib/makit/tasks/init.rb +49 -49
- data/lib/makit/tasks/integrate.rb +29 -29
- data/lib/makit/tasks/pull_incoming.rb +13 -13
- data/lib/makit/tasks/setup.rb +13 -13
- data/lib/makit/tasks/sync.rb +17 -17
- data/lib/makit/tasks/tag.rb +16 -16
- data/lib/makit/tasks/task_monkey_patch.rb +81 -81
- data/lib/makit/tasks/test.rb +22 -22
- data/lib/makit/tasks/update.rb +18 -18
- data/lib/makit/tasks.rb +20 -20
- data/lib/makit/test_cache.rb +239 -239
- data/lib/makit/tree.rb +37 -37
- data/lib/makit/v1/makit.v1_pb.rb +35 -35
- data/lib/makit/v1/makit.v1_services_pb.rb +27 -27
- data/lib/makit/version.rb +99 -99
- data/lib/makit/version_util.rb +21 -21
- data/lib/makit/wix.rb +95 -95
- data/lib/makit/yaml.rb +29 -29
- data/lib/makit/zip.rb +17 -17
- data/lib/makit copy.rb +44 -44
- data/lib/makit.rb +42 -42
- metadata +2 -2
@@ -1,308 +1,308 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Makit
|
4
|
-
module Logging
|
5
|
-
# Configuration management for unified logging
|
6
|
-
#
|
7
|
-
# Provides schema validation, default configurations, and helper methods
|
8
|
-
# for setting up the unified file sink with various output configurations.
|
9
|
-
#
|
10
|
-
# @example Basic configuration
|
11
|
-
# config = Configuration.new(
|
12
|
-
# configurations: [
|
13
|
-
# { file: $stdout, format: :console },
|
14
|
-
# { file: "logs/app.log", format: :json }
|
15
|
-
# ]
|
16
|
-
# )
|
17
|
-
#
|
18
|
-
# @example YAML configuration
|
19
|
-
# config = Configuration.from_yaml("config/logging.yml")
|
20
|
-
#
|
21
|
-
# @example Environment-based configuration
|
22
|
-
# config = Configuration.for_environment(:production)
|
23
|
-
class Configuration
|
24
|
-
# @return [Array<Hash>] list of output configurations
|
25
|
-
attr_reader :configurations
|
26
|
-
|
27
|
-
# Initialize configuration
|
28
|
-
#
|
29
|
-
# @param configurations [Array<Hash>] list of output configurations
|
30
|
-
def initialize(configurations: [])
|
31
|
-
@configurations = configurations
|
32
|
-
end
|
33
|
-
|
34
|
-
# Create configuration from YAML file
|
35
|
-
#
|
36
|
-
# @param yaml_file [String] path to YAML configuration file
|
37
|
-
# @return [Configuration] new configuration instance
|
38
|
-
def self.from_yaml(yaml_file)
|
39
|
-
require "yaml"
|
40
|
-
data = YAML.load_file(yaml_file)
|
41
|
-
configurations = data["logging"]["sinks"] || []
|
42
|
-
|
43
|
-
# Convert string keys to symbols
|
44
|
-
configurations = configurations.map do |config|
|
45
|
-
config.transform_keys(&:to_sym)
|
46
|
-
end
|
47
|
-
|
48
|
-
new(configurations: configurations)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Create configuration from JSON file
|
52
|
-
#
|
53
|
-
# @param json_file [String] path to JSON configuration file
|
54
|
-
# @return [Configuration] new configuration instance
|
55
|
-
def self.from_json(json_file)
|
56
|
-
require "json"
|
57
|
-
data = JSON.parse(File.read(json_file))
|
58
|
-
configurations = data["logging"]["sinks"] || []
|
59
|
-
|
60
|
-
# Convert string keys to symbols
|
61
|
-
configurations = configurations.map do |config|
|
62
|
-
config.transform_keys(&:to_sym)
|
63
|
-
end
|
64
|
-
|
65
|
-
new(configurations: configurations)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Create environment-specific configuration
|
69
|
-
#
|
70
|
-
# @param environment [Symbol] environment name (:development, :production, :test)
|
71
|
-
# @return [Configuration] new configuration instance
|
72
|
-
def self.for_environment(environment)
|
73
|
-
case environment
|
74
|
-
when :development
|
75
|
-
development_config
|
76
|
-
when :production
|
77
|
-
production_config
|
78
|
-
when :test
|
79
|
-
test_config
|
80
|
-
when :ci
|
81
|
-
ci_config
|
82
|
-
else
|
83
|
-
default_config
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# Get default configuration
|
88
|
-
#
|
89
|
-
# @return [Configuration] default configuration
|
90
|
-
def self.default_config
|
91
|
-
new(
|
92
|
-
configurations: [
|
93
|
-
{ file: $stdout, format: :console },
|
94
|
-
{ file: "artifacts/makit.log", format: :json, append: true },
|
95
|
-
],
|
96
|
-
)
|
97
|
-
end
|
98
|
-
|
99
|
-
# Get development configuration
|
100
|
-
#
|
101
|
-
# @return [Configuration] development configuration
|
102
|
-
def self.development_config
|
103
|
-
new(
|
104
|
-
configurations: [
|
105
|
-
{
|
106
|
-
file: $stdout,
|
107
|
-
format: :console,
|
108
|
-
show_timestamp: true,
|
109
|
-
show_level: true,
|
110
|
-
},
|
111
|
-
{
|
112
|
-
file: "logs/development.log",
|
113
|
-
format: :text,
|
114
|
-
append: true,
|
115
|
-
include_context: true,
|
116
|
-
},
|
117
|
-
{
|
118
|
-
file: "logs/debug.log",
|
119
|
-
format: :json,
|
120
|
-
append: true,
|
121
|
-
min_level: :debug,
|
122
|
-
},
|
123
|
-
],
|
124
|
-
)
|
125
|
-
end
|
126
|
-
|
127
|
-
# Get production configuration
|
128
|
-
#
|
129
|
-
# @return [Configuration] production configuration
|
130
|
-
def self.production_config
|
131
|
-
new(
|
132
|
-
configurations: [
|
133
|
-
{
|
134
|
-
file: "logs/application.log",
|
135
|
-
format: :json,
|
136
|
-
append: true,
|
137
|
-
include_metadata: true,
|
138
|
-
rotation: { max_size: "100MB", max_files: 10 },
|
139
|
-
},
|
140
|
-
{
|
141
|
-
file: "logs/errors.log",
|
142
|
-
format: :json,
|
143
|
-
append: true,
|
144
|
-
min_level: :error,
|
145
|
-
include_metadata: true,
|
146
|
-
},
|
147
|
-
],
|
148
|
-
)
|
149
|
-
end
|
150
|
-
|
151
|
-
# Get test configuration
|
152
|
-
#
|
153
|
-
# @return [Configuration] test configuration
|
154
|
-
def self.test_config
|
155
|
-
new(
|
156
|
-
configurations: [
|
157
|
-
{
|
158
|
-
file: "logs/test.log",
|
159
|
-
format: :text,
|
160
|
-
append: false,
|
161
|
-
include_context: true,
|
162
|
-
},
|
163
|
-
],
|
164
|
-
)
|
165
|
-
end
|
166
|
-
|
167
|
-
# Get CI/CD configuration
|
168
|
-
#
|
169
|
-
# @return [Configuration] CI configuration
|
170
|
-
def self.ci_config
|
171
|
-
new(
|
172
|
-
configurations: [
|
173
|
-
{
|
174
|
-
file: $stdout,
|
175
|
-
format: :console,
|
176
|
-
show_level: true,
|
177
|
-
},
|
178
|
-
{
|
179
|
-
file: "artifacts/build.log",
|
180
|
-
format: :json,
|
181
|
-
append: true,
|
182
|
-
include_metadata: true,
|
183
|
-
},
|
184
|
-
],
|
185
|
-
)
|
186
|
-
end
|
187
|
-
|
188
|
-
# Validate configuration
|
189
|
-
#
|
190
|
-
# @return [Boolean] true if valid
|
191
|
-
# @raise [ArgumentError] if configuration is invalid
|
192
|
-
def validate!
|
193
|
-
raise ArgumentError, "configurations must be an array" unless @configurations.is_a?(Array)
|
194
|
-
raise ArgumentError, "at least one configuration is required" if @configurations.empty?
|
195
|
-
|
196
|
-
@configurations.each_with_index do |config, index|
|
197
|
-
validate_single_configuration(config, index)
|
198
|
-
end
|
199
|
-
|
200
|
-
true
|
201
|
-
end
|
202
|
-
|
203
|
-
# Check if configuration is valid
|
204
|
-
#
|
205
|
-
# @return [Boolean] true if valid
|
206
|
-
def valid?
|
207
|
-
validate!
|
208
|
-
true
|
209
|
-
rescue ArgumentError
|
210
|
-
false
|
211
|
-
end
|
212
|
-
|
213
|
-
# Get configuration as hash
|
214
|
-
#
|
215
|
-
# @return [Hash] configuration as hash
|
216
|
-
def to_hash
|
217
|
-
{
|
218
|
-
logging: {
|
219
|
-
sinks: @configurations,
|
220
|
-
},
|
221
|
-
}
|
222
|
-
end
|
223
|
-
|
224
|
-
# Save configuration to YAML file
|
225
|
-
#
|
226
|
-
# @param yaml_file [String] path to YAML file
|
227
|
-
# @return [void]
|
228
|
-
def save_yaml(yaml_file)
|
229
|
-
require "yaml"
|
230
|
-
FileUtils.mkdir_p(File.dirname(yaml_file))
|
231
|
-
File.write(yaml_file, to_hash.to_yaml)
|
232
|
-
end
|
233
|
-
|
234
|
-
# Save configuration to JSON file
|
235
|
-
#
|
236
|
-
# @param json_file [String] path to JSON file
|
237
|
-
# @return [void]
|
238
|
-
def save_json(json_file)
|
239
|
-
require "json"
|
240
|
-
FileUtils.mkdir_p(File.dirname(json_file))
|
241
|
-
File.write(json_file, JSON.pretty_generate(to_hash))
|
242
|
-
end
|
243
|
-
|
244
|
-
private
|
245
|
-
|
246
|
-
# Validate a single configuration
|
247
|
-
#
|
248
|
-
# @param config [Hash] configuration to validate
|
249
|
-
# @param index [Integer] configuration index for error messages
|
250
|
-
# @raise [ArgumentError] if configuration is invalid
|
251
|
-
def validate_single_configuration(config, index)
|
252
|
-
raise ArgumentError, "configuration #{index} must be a hash" unless config.is_a?(Hash)
|
253
|
-
|
254
|
-
required_keys = %i[file format]
|
255
|
-
missing_keys = required_keys - config.keys
|
256
|
-
unless missing_keys.empty?
|
257
|
-
raise ArgumentError,
|
258
|
-
"configuration #{index} missing required keys: #{missing_keys.join(", ")}"
|
259
|
-
end
|
260
|
-
|
261
|
-
# Validate file
|
262
|
-
file = config[:file]
|
263
|
-
unless file.is_a?(String) || file.is_a?(IO) || file.respond_to?(:write)
|
264
|
-
raise ArgumentError, "configuration #{index} file must be a String path, IO object, or writable object"
|
265
|
-
end
|
266
|
-
|
267
|
-
# Validate format
|
268
|
-
format = config[:format]
|
269
|
-
unless format.is_a?(Symbol) || format.is_a?(String)
|
270
|
-
raise ArgumentError, "configuration #{index} format must be a Symbol or String"
|
271
|
-
end
|
272
|
-
|
273
|
-
# Validate log levels if specified
|
274
|
-
if config[:min_level] && !valid_log_level?(config[:min_level])
|
275
|
-
raise ArgumentError, "configuration #{index} min_level must be a valid log level"
|
276
|
-
end
|
277
|
-
|
278
|
-
if config[:max_level] && !valid_log_level?(config[:max_level])
|
279
|
-
raise ArgumentError, "configuration #{index} max_level must be a valid log level"
|
280
|
-
end
|
281
|
-
|
282
|
-
# Validate rotation if specified
|
283
|
-
return unless config[:rotation] && !valid_rotation_config?(config[:rotation])
|
284
|
-
|
285
|
-
raise ArgumentError, "configuration #{index} rotation must be a valid rotation configuration"
|
286
|
-
end
|
287
|
-
|
288
|
-
# Check if log level is valid
|
289
|
-
#
|
290
|
-
# @param level [Symbol] log level to check
|
291
|
-
# @return [Boolean] true if valid
|
292
|
-
def valid_log_level?(level)
|
293
|
-
%i[debug info warn error fatal success].include?(level)
|
294
|
-
end
|
295
|
-
|
296
|
-
# Check if rotation configuration is valid
|
297
|
-
#
|
298
|
-
# @param rotation [Hash] rotation configuration
|
299
|
-
# @return [Boolean] true if valid
|
300
|
-
def valid_rotation_config?(rotation)
|
301
|
-
return false unless rotation.is_a?(Hash)
|
302
|
-
|
303
|
-
valid_keys = %i[max_size max_files compress pattern]
|
304
|
-
rotation.keys.all? { |key| valid_keys.include?(key) }
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Makit
|
4
|
+
module Logging
|
5
|
+
# Configuration management for unified logging
|
6
|
+
#
|
7
|
+
# Provides schema validation, default configurations, and helper methods
|
8
|
+
# for setting up the unified file sink with various output configurations.
|
9
|
+
#
|
10
|
+
# @example Basic configuration
|
11
|
+
# config = Configuration.new(
|
12
|
+
# configurations: [
|
13
|
+
# { file: $stdout, format: :console },
|
14
|
+
# { file: "logs/app.log", format: :json }
|
15
|
+
# ]
|
16
|
+
# )
|
17
|
+
#
|
18
|
+
# @example YAML configuration
|
19
|
+
# config = Configuration.from_yaml("config/logging.yml")
|
20
|
+
#
|
21
|
+
# @example Environment-based configuration
|
22
|
+
# config = Configuration.for_environment(:production)
|
23
|
+
class Configuration
|
24
|
+
# @return [Array<Hash>] list of output configurations
|
25
|
+
attr_reader :configurations
|
26
|
+
|
27
|
+
# Initialize configuration
|
28
|
+
#
|
29
|
+
# @param configurations [Array<Hash>] list of output configurations
|
30
|
+
def initialize(configurations: [])
|
31
|
+
@configurations = configurations
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create configuration from YAML file
|
35
|
+
#
|
36
|
+
# @param yaml_file [String] path to YAML configuration file
|
37
|
+
# @return [Configuration] new configuration instance
|
38
|
+
def self.from_yaml(yaml_file)
|
39
|
+
require "yaml"
|
40
|
+
data = YAML.load_file(yaml_file)
|
41
|
+
configurations = data["logging"]["sinks"] || []
|
42
|
+
|
43
|
+
# Convert string keys to symbols
|
44
|
+
configurations = configurations.map do |config|
|
45
|
+
config.transform_keys(&:to_sym)
|
46
|
+
end
|
47
|
+
|
48
|
+
new(configurations: configurations)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create configuration from JSON file
|
52
|
+
#
|
53
|
+
# @param json_file [String] path to JSON configuration file
|
54
|
+
# @return [Configuration] new configuration instance
|
55
|
+
def self.from_json(json_file)
|
56
|
+
require "json"
|
57
|
+
data = JSON.parse(File.read(json_file))
|
58
|
+
configurations = data["logging"]["sinks"] || []
|
59
|
+
|
60
|
+
# Convert string keys to symbols
|
61
|
+
configurations = configurations.map do |config|
|
62
|
+
config.transform_keys(&:to_sym)
|
63
|
+
end
|
64
|
+
|
65
|
+
new(configurations: configurations)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Create environment-specific configuration
|
69
|
+
#
|
70
|
+
# @param environment [Symbol] environment name (:development, :production, :test)
|
71
|
+
# @return [Configuration] new configuration instance
|
72
|
+
def self.for_environment(environment)
|
73
|
+
case environment
|
74
|
+
when :development
|
75
|
+
development_config
|
76
|
+
when :production
|
77
|
+
production_config
|
78
|
+
when :test
|
79
|
+
test_config
|
80
|
+
when :ci
|
81
|
+
ci_config
|
82
|
+
else
|
83
|
+
default_config
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Get default configuration
|
88
|
+
#
|
89
|
+
# @return [Configuration] default configuration
|
90
|
+
def self.default_config
|
91
|
+
new(
|
92
|
+
configurations: [
|
93
|
+
{ file: $stdout, format: :console },
|
94
|
+
{ file: "artifacts/makit.log", format: :json, append: true },
|
95
|
+
],
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Get development configuration
|
100
|
+
#
|
101
|
+
# @return [Configuration] development configuration
|
102
|
+
def self.development_config
|
103
|
+
new(
|
104
|
+
configurations: [
|
105
|
+
{
|
106
|
+
file: $stdout,
|
107
|
+
format: :console,
|
108
|
+
show_timestamp: true,
|
109
|
+
show_level: true,
|
110
|
+
},
|
111
|
+
{
|
112
|
+
file: "logs/development.log",
|
113
|
+
format: :text,
|
114
|
+
append: true,
|
115
|
+
include_context: true,
|
116
|
+
},
|
117
|
+
{
|
118
|
+
file: "logs/debug.log",
|
119
|
+
format: :json,
|
120
|
+
append: true,
|
121
|
+
min_level: :debug,
|
122
|
+
},
|
123
|
+
],
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Get production configuration
|
128
|
+
#
|
129
|
+
# @return [Configuration] production configuration
|
130
|
+
def self.production_config
|
131
|
+
new(
|
132
|
+
configurations: [
|
133
|
+
{
|
134
|
+
file: "logs/application.log",
|
135
|
+
format: :json,
|
136
|
+
append: true,
|
137
|
+
include_metadata: true,
|
138
|
+
rotation: { max_size: "100MB", max_files: 10 },
|
139
|
+
},
|
140
|
+
{
|
141
|
+
file: "logs/errors.log",
|
142
|
+
format: :json,
|
143
|
+
append: true,
|
144
|
+
min_level: :error,
|
145
|
+
include_metadata: true,
|
146
|
+
},
|
147
|
+
],
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Get test configuration
|
152
|
+
#
|
153
|
+
# @return [Configuration] test configuration
|
154
|
+
def self.test_config
|
155
|
+
new(
|
156
|
+
configurations: [
|
157
|
+
{
|
158
|
+
file: "logs/test.log",
|
159
|
+
format: :text,
|
160
|
+
append: false,
|
161
|
+
include_context: true,
|
162
|
+
},
|
163
|
+
],
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Get CI/CD configuration
|
168
|
+
#
|
169
|
+
# @return [Configuration] CI configuration
|
170
|
+
def self.ci_config
|
171
|
+
new(
|
172
|
+
configurations: [
|
173
|
+
{
|
174
|
+
file: $stdout,
|
175
|
+
format: :console,
|
176
|
+
show_level: true,
|
177
|
+
},
|
178
|
+
{
|
179
|
+
file: "artifacts/build.log",
|
180
|
+
format: :json,
|
181
|
+
append: true,
|
182
|
+
include_metadata: true,
|
183
|
+
},
|
184
|
+
],
|
185
|
+
)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Validate configuration
|
189
|
+
#
|
190
|
+
# @return [Boolean] true if valid
|
191
|
+
# @raise [ArgumentError] if configuration is invalid
|
192
|
+
def validate!
|
193
|
+
raise ArgumentError, "configurations must be an array" unless @configurations.is_a?(Array)
|
194
|
+
raise ArgumentError, "at least one configuration is required" if @configurations.empty?
|
195
|
+
|
196
|
+
@configurations.each_with_index do |config, index|
|
197
|
+
validate_single_configuration(config, index)
|
198
|
+
end
|
199
|
+
|
200
|
+
true
|
201
|
+
end
|
202
|
+
|
203
|
+
# Check if configuration is valid
|
204
|
+
#
|
205
|
+
# @return [Boolean] true if valid
|
206
|
+
def valid?
|
207
|
+
validate!
|
208
|
+
true
|
209
|
+
rescue ArgumentError
|
210
|
+
false
|
211
|
+
end
|
212
|
+
|
213
|
+
# Get configuration as hash
|
214
|
+
#
|
215
|
+
# @return [Hash] configuration as hash
|
216
|
+
def to_hash
|
217
|
+
{
|
218
|
+
logging: {
|
219
|
+
sinks: @configurations,
|
220
|
+
},
|
221
|
+
}
|
222
|
+
end
|
223
|
+
|
224
|
+
# Save configuration to YAML file
|
225
|
+
#
|
226
|
+
# @param yaml_file [String] path to YAML file
|
227
|
+
# @return [void]
|
228
|
+
def save_yaml(yaml_file)
|
229
|
+
require "yaml"
|
230
|
+
FileUtils.mkdir_p(File.dirname(yaml_file))
|
231
|
+
File.write(yaml_file, to_hash.to_yaml)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Save configuration to JSON file
|
235
|
+
#
|
236
|
+
# @param json_file [String] path to JSON file
|
237
|
+
# @return [void]
|
238
|
+
def save_json(json_file)
|
239
|
+
require "json"
|
240
|
+
FileUtils.mkdir_p(File.dirname(json_file))
|
241
|
+
File.write(json_file, JSON.pretty_generate(to_hash))
|
242
|
+
end
|
243
|
+
|
244
|
+
private
|
245
|
+
|
246
|
+
# Validate a single configuration
|
247
|
+
#
|
248
|
+
# @param config [Hash] configuration to validate
|
249
|
+
# @param index [Integer] configuration index for error messages
|
250
|
+
# @raise [ArgumentError] if configuration is invalid
|
251
|
+
def validate_single_configuration(config, index)
|
252
|
+
raise ArgumentError, "configuration #{index} must be a hash" unless config.is_a?(Hash)
|
253
|
+
|
254
|
+
required_keys = %i[file format]
|
255
|
+
missing_keys = required_keys - config.keys
|
256
|
+
unless missing_keys.empty?
|
257
|
+
raise ArgumentError,
|
258
|
+
"configuration #{index} missing required keys: #{missing_keys.join(", ")}"
|
259
|
+
end
|
260
|
+
|
261
|
+
# Validate file
|
262
|
+
file = config[:file]
|
263
|
+
unless file.is_a?(String) || file.is_a?(IO) || file.respond_to?(:write)
|
264
|
+
raise ArgumentError, "configuration #{index} file must be a String path, IO object, or writable object"
|
265
|
+
end
|
266
|
+
|
267
|
+
# Validate format
|
268
|
+
format = config[:format]
|
269
|
+
unless format.is_a?(Symbol) || format.is_a?(String)
|
270
|
+
raise ArgumentError, "configuration #{index} format must be a Symbol or String"
|
271
|
+
end
|
272
|
+
|
273
|
+
# Validate log levels if specified
|
274
|
+
if config[:min_level] && !valid_log_level?(config[:min_level])
|
275
|
+
raise ArgumentError, "configuration #{index} min_level must be a valid log level"
|
276
|
+
end
|
277
|
+
|
278
|
+
if config[:max_level] && !valid_log_level?(config[:max_level])
|
279
|
+
raise ArgumentError, "configuration #{index} max_level must be a valid log level"
|
280
|
+
end
|
281
|
+
|
282
|
+
# Validate rotation if specified
|
283
|
+
return unless config[:rotation] && !valid_rotation_config?(config[:rotation])
|
284
|
+
|
285
|
+
raise ArgumentError, "configuration #{index} rotation must be a valid rotation configuration"
|
286
|
+
end
|
287
|
+
|
288
|
+
# Check if log level is valid
|
289
|
+
#
|
290
|
+
# @param level [Symbol] log level to check
|
291
|
+
# @return [Boolean] true if valid
|
292
|
+
def valid_log_level?(level)
|
293
|
+
%i[debug info warn error fatal success].include?(level)
|
294
|
+
end
|
295
|
+
|
296
|
+
# Check if rotation configuration is valid
|
297
|
+
#
|
298
|
+
# @param rotation [Hash] rotation configuration
|
299
|
+
# @return [Boolean] true if valid
|
300
|
+
def valid_rotation_config?(rotation)
|
301
|
+
return false unless rotation.is_a?(Hash)
|
302
|
+
|
303
|
+
valid_keys = %i[max_size max_files compress pattern]
|
304
|
+
rotation.keys.all? { |key| valid_keys.include?(key) }
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|