makit 0.0.111 → 0.0.112
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/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 +62 -62
- data/lib/makit/cli/project_commands.rb +868 -868
- data/lib/makit/cli/repository_commands.rb +661 -661
- 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 +320 -323
- data/lib/makit/commands/middleware/unified_logger.rb +243 -243
- data/lib/makit/commands/middleware/validator.rb +269 -269
- data/lib/makit/commands/request.rb +254 -254
- data/lib/makit/commands/result.rb +323 -323
- data/lib/makit/commands/runner.rb +337 -317
- data/lib/makit/commands/strategies/base.rb +160 -160
- data/lib/makit/commands/strategies/synchronous.rb +134 -134
- data/lib/makit/commands.rb +51 -42
- data/lib/makit/configuration/gitlab_helper.rb +60 -60
- data/lib/makit/configuration/project.rb +127 -127
- data/lib/makit/configuration/rakefile_helper.rb +43 -43
- data/lib/makit/configuration/step.rb +34 -34
- data/lib/makit/configuration.rb +14 -14
- data/lib/makit/content/default_gitignore.rb +7 -7
- 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 +141 -141
- 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/project.rb +153 -153
- 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 +305 -305
- data/lib/makit/logging/formatters/base.rb +39 -39
- data/lib/makit/logging/formatters/console_formatter.rb +140 -127
- 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 +115 -115
- data/lib/makit/logging/logger.rb +163 -159
- data/lib/makit/logging/sinks/console.rb +72 -72
- data/lib/makit/logging/sinks/file_sink.rb +92 -92
- data/lib/makit/logging/sinks/unified_file_sink.rb +303 -303
- data/lib/makit/logging.rb +530 -521
- 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 +193 -348
- 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.rb +25 -25
- 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 -117
- data/lib/makit/services/builder.rb +186 -186
- data/lib/makit/services/error_handler.rb +226 -226
- data/lib/makit/services/repository_manager.rb +229 -229
- data/lib/makit/services/validator.rb +112 -112
- data/lib/makit/setup/classlib.rb +53 -53
- data/lib/makit/setup/gem.rb +30 -17
- data/lib/makit/setup/runner.rb +45 -40
- data/lib/makit/setup.rb +5 -0
- data/lib/makit/show.rb +110 -110
- data/lib/makit/storage.rb +126 -126
- data/lib/makit/symbols.rb +170 -161
- data/lib/makit/task_info.rb +128 -128
- data/lib/makit/tasks/at_exit.rb +13 -13
- data/lib/makit/tasks/build.rb +19 -18
- data/lib/makit/tasks/clean.rb +11 -11
- data/lib/makit/tasks/hook_manager.rb +393 -239
- data/lib/makit/tasks/init.rb +47 -47
- data/lib/makit/tasks/integrate.rb +17 -15
- data/lib/makit/tasks/pull_incoming.rb +11 -12
- data/lib/makit/tasks/setup.rb +6 -6
- data/lib/makit/tasks/sync.rb +12 -11
- data/lib/makit/tasks/tag.rb +15 -0
- data/lib/makit/tasks/task_monkey_patch.rb +79 -79
- data/lib/makit/tasks.rb +10 -0
- data/lib/makit/test_cache.rb +239 -239
- data/lib/makit/tree.rb +37 -37
- data/lib/makit/v1/makit.v1_pb.rb +34 -34
- data/lib/makit/v1/makit.v1_services_pb.rb +27 -27
- data/lib/makit/version.rb +5 -5
- data/lib/makit/version_util.rb +21 -0
- 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 -0
- data/lib/makit.rb +40 -8
- metadata +50 -7
- data/lib/makit/command_runner.rb +0 -463
- data/lib/makit/commands/compatibility.rb +0 -365
- data/lib/makit/task_hooks.rb +0 -125
data/lib/makit/logging/logger.rb
CHANGED
@@ -1,159 +1,163 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "set"
|
4
|
-
require_relative "log_request"
|
5
|
-
require_relative "sinks/base"
|
6
|
-
require_relative "sinks/console"
|
7
|
-
require_relative "sinks/file_sink"
|
8
|
-
require_relative "sinks/structured"
|
9
|
-
|
10
|
-
module Makit
|
11
|
-
module Logging
|
12
|
-
# Main logger class that orchestrates logging through sinks
|
13
|
-
#
|
14
|
-
# This class provides a clean interface for logging with support for
|
15
|
-
# sink-based output processing. It follows the same pattern as the
|
16
|
-
# Commands::Runner but for logging operations.
|
17
|
-
#
|
18
|
-
# @example Basic usage
|
19
|
-
# logger = Logger.new
|
20
|
-
# logger.info("Processing started")
|
21
|
-
#
|
22
|
-
# @example With custom sinks
|
23
|
-
# logger = Logger.new(
|
24
|
-
# sinks: [
|
25
|
-
# Sinks::Console.new,
|
26
|
-
# Sinks::File.new(log_file: "custom.log")
|
27
|
-
# ]
|
28
|
-
# )
|
29
|
-
#
|
30
|
-
# @example Using convenience methods
|
31
|
-
# logger.success("Build completed")
|
32
|
-
# logger.error("Build failed", { repository: "user/repo" })
|
33
|
-
class Logger
|
34
|
-
# @return [Array<Sinks::Base>] list of sinks to process log requests
|
35
|
-
attr_reader :sinks
|
36
|
-
# @return [Symbol] minimum log level for filtering
|
37
|
-
attr_reader :level
|
38
|
-
|
39
|
-
# Initialize the logger with sinks and log level
|
40
|
-
#
|
41
|
-
# @param sinks [Array<Sinks::Base>] list of sinks to use
|
42
|
-
# @param level [Symbol] minimum log level (:debug, :info, :warn, :error, :fatal, :success)
|
43
|
-
def initialize(sinks: [], level: :info)
|
44
|
-
@sinks = sinks
|
45
|
-
@level = level
|
46
|
-
@logged_tasks = Set.new
|
47
|
-
end
|
48
|
-
|
49
|
-
# Log a message with the specified level
|
50
|
-
#
|
51
|
-
# @param level [Symbol] the log level (:debug, :info, :warn, :error, :fatal, :success)
|
52
|
-
# @param message [String] the log message
|
53
|
-
# @param context [Hash] additional context information
|
54
|
-
# @return [void]
|
55
|
-
def log(level, message, context = {})
|
56
|
-
return unless should_log?(level)
|
57
|
-
|
58
|
-
log_request = LogRequest.new(level, message, context)
|
59
|
-
execute_sinks(log_request)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Log an info message
|
63
|
-
#
|
64
|
-
# @param message [String] the log message
|
65
|
-
# @param context [Hash] additional context information
|
66
|
-
# @return [void]
|
67
|
-
def info(message, context = {})
|
68
|
-
log(:info, message, context)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Log a success message
|
72
|
-
#
|
73
|
-
# @param message [String] the log message
|
74
|
-
# @param context [Hash] additional context information
|
75
|
-
# @return [void]
|
76
|
-
def success(message, context = {})
|
77
|
-
log(:success, message, context)
|
78
|
-
end
|
79
|
-
|
80
|
-
# Log an error message
|
81
|
-
#
|
82
|
-
# @param message [String] the log message
|
83
|
-
# @param context [Hash] additional context information
|
84
|
-
# @return [void]
|
85
|
-
def error(message, context = {})
|
86
|
-
log(:error, message, context)
|
87
|
-
end
|
88
|
-
|
89
|
-
# Log a warning message
|
90
|
-
#
|
91
|
-
# @param message [String] the log message
|
92
|
-
# @param context [Hash] additional context information
|
93
|
-
# @return [void]
|
94
|
-
def warn(message, context = {})
|
95
|
-
log(:warn, message, context)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Log a debug message
|
99
|
-
#
|
100
|
-
# @param message [String] the log message
|
101
|
-
# @param context [Hash] additional context information
|
102
|
-
# @return [void]
|
103
|
-
def debug(message, context = {})
|
104
|
-
log(:debug, message, context)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Log a fatal message
|
108
|
-
#
|
109
|
-
# @param message [String] the log message
|
110
|
-
# @param context [Hash] additional context information
|
111
|
-
# @return [void]
|
112
|
-
def fatal(message, context = {})
|
113
|
-
log(:fatal, message, context)
|
114
|
-
end
|
115
|
-
|
116
|
-
def task_start(message, context = {})
|
117
|
-
return if @logged_tasks.include?(message)
|
118
|
-
@logged_tasks.add(message)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
require_relative "log_request"
|
5
|
+
require_relative "sinks/base"
|
6
|
+
require_relative "sinks/console"
|
7
|
+
require_relative "sinks/file_sink"
|
8
|
+
require_relative "sinks/structured"
|
9
|
+
|
10
|
+
module Makit
|
11
|
+
module Logging
|
12
|
+
# Main logger class that orchestrates logging through sinks
|
13
|
+
#
|
14
|
+
# This class provides a clean interface for logging with support for
|
15
|
+
# sink-based output processing. It follows the same pattern as the
|
16
|
+
# Commands::Runner but for logging operations.
|
17
|
+
#
|
18
|
+
# @example Basic usage
|
19
|
+
# logger = Logger.new
|
20
|
+
# logger.info("Processing started")
|
21
|
+
#
|
22
|
+
# @example With custom sinks
|
23
|
+
# logger = Logger.new(
|
24
|
+
# sinks: [
|
25
|
+
# Sinks::Console.new,
|
26
|
+
# Sinks::File.new(log_file: "custom.log")
|
27
|
+
# ]
|
28
|
+
# )
|
29
|
+
#
|
30
|
+
# @example Using convenience methods
|
31
|
+
# logger.success("Build completed")
|
32
|
+
# logger.error("Build failed", { repository: "user/repo" })
|
33
|
+
class Logger
|
34
|
+
# @return [Array<Sinks::Base>] list of sinks to process log requests
|
35
|
+
attr_reader :sinks
|
36
|
+
# @return [Symbol] minimum log level for filtering
|
37
|
+
attr_reader :level
|
38
|
+
|
39
|
+
# Initialize the logger with sinks and log level
|
40
|
+
#
|
41
|
+
# @param sinks [Array<Sinks::Base>] list of sinks to use
|
42
|
+
# @param level [Symbol] minimum log level (:debug, :info, :warn, :error, :fatal, :success)
|
43
|
+
def initialize(sinks: [], level: :info)
|
44
|
+
@sinks = sinks
|
45
|
+
@level = level
|
46
|
+
@logged_tasks = Set.new
|
47
|
+
end
|
48
|
+
|
49
|
+
# Log a message with the specified level
|
50
|
+
#
|
51
|
+
# @param level [Symbol] the log level (:debug, :info, :warn, :error, :fatal, :success)
|
52
|
+
# @param message [String] the log message
|
53
|
+
# @param context [Hash] additional context information
|
54
|
+
# @return [void]
|
55
|
+
def log(level, message, context = {})
|
56
|
+
return unless should_log?(level)
|
57
|
+
|
58
|
+
log_request = LogRequest.new(level, message, context)
|
59
|
+
execute_sinks(log_request)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Log an info message
|
63
|
+
#
|
64
|
+
# @param message [String] the log message
|
65
|
+
# @param context [Hash] additional context information
|
66
|
+
# @return [void]
|
67
|
+
def info(message, context = {})
|
68
|
+
log(:info, message, context)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Log a success message
|
72
|
+
#
|
73
|
+
# @param message [String] the log message
|
74
|
+
# @param context [Hash] additional context information
|
75
|
+
# @return [void]
|
76
|
+
def success(message, context = {})
|
77
|
+
log(:success, message, context)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Log an error message
|
81
|
+
#
|
82
|
+
# @param message [String] the log message
|
83
|
+
# @param context [Hash] additional context information
|
84
|
+
# @return [void]
|
85
|
+
def error(message, context = {})
|
86
|
+
log(:error, message, context)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Log a warning message
|
90
|
+
#
|
91
|
+
# @param message [String] the log message
|
92
|
+
# @param context [Hash] additional context information
|
93
|
+
# @return [void]
|
94
|
+
def warn(message, context = {})
|
95
|
+
log(:warn, message, context)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Log a debug message
|
99
|
+
#
|
100
|
+
# @param message [String] the log message
|
101
|
+
# @param context [Hash] additional context information
|
102
|
+
# @return [void]
|
103
|
+
def debug(message, context = {})
|
104
|
+
log(:debug, message, context)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Log a fatal message
|
108
|
+
#
|
109
|
+
# @param message [String] the log message
|
110
|
+
# @param context [Hash] additional context information
|
111
|
+
# @return [void]
|
112
|
+
def fatal(message, context = {})
|
113
|
+
log(:fatal, message, context)
|
114
|
+
end
|
115
|
+
|
116
|
+
def task_start(message, context = {})
|
117
|
+
return if @logged_tasks.include?(message)
|
118
|
+
@logged_tasks.add(message)
|
119
|
+
# Format task name with colon prefix and bold white styling
|
120
|
+
formatted_message = ": #{message}".colorize(:white).bold
|
121
|
+
# Add special context to identify task messages
|
122
|
+
task_context = context.merge(task_message: true)
|
123
|
+
log(:info, formatted_message, task_context)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Get logger configuration
|
127
|
+
#
|
128
|
+
# @return [Hash] logger configuration
|
129
|
+
def config
|
130
|
+
{
|
131
|
+
level: @level,
|
132
|
+
sinks_count: @sinks.length,
|
133
|
+
sinks: @sinks.map(&:config),
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
# Check if a log level should be processed
|
140
|
+
#
|
141
|
+
# @param level [Symbol] the log level to check
|
142
|
+
# @return [Boolean] true if the level should be logged
|
143
|
+
def should_log?(level)
|
144
|
+
levels = [:debug, :info, :warn, :error, :fatal, :success]
|
145
|
+
levels.index(level) >= levels.index(@level)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Execute the sink chain for a log request
|
149
|
+
#
|
150
|
+
# @param log_request [LogRequest] the log request to process
|
151
|
+
# @return [void]
|
152
|
+
def execute_sinks(log_request)
|
153
|
+
# Filter applicable sinks
|
154
|
+
applicable_sinks = @sinks.select { |s| s.applicable?(log_request) }
|
155
|
+
|
156
|
+
# Execute sink chain
|
157
|
+
applicable_sinks.reduce(log_request) do |request, sink|
|
158
|
+
sink.call(request)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -1,72 +1,72 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "unified_file_sink"
|
4
|
-
|
5
|
-
module Makit
|
6
|
-
module Logging
|
7
|
-
module Sinks
|
8
|
-
# Console sink for clean, colored log output
|
9
|
-
#
|
10
|
-
# This is a thin wrapper around UnifiedFileSink that provides a simple
|
11
|
-
# API for console output. It maintains backward compatibility while
|
12
|
-
# leveraging the unified logging architecture.
|
13
|
-
#
|
14
|
-
# @example Basic usage
|
15
|
-
# console = Console.new
|
16
|
-
# logger = Logger.new(sinks: [console])
|
17
|
-
# logger.info("Processing started")
|
18
|
-
# # Shows: → Processing started
|
19
|
-
#
|
20
|
-
# @example With custom formatter options
|
21
|
-
# console = Console.new(show_timestamp: true, show_level: true)
|
22
|
-
#
|
23
|
-
# @example With custom formatter
|
24
|
-
# console = Console.new(formatter: :text)
|
25
|
-
class Console < UnifiedFileSink
|
26
|
-
# @return [Symbol] the format being used
|
27
|
-
attr_reader :format
|
28
|
-
|
29
|
-
# Initialize console sink
|
30
|
-
#
|
31
|
-
# @param formatter [Symbol, String] formatter name (default: :console)
|
32
|
-
# @param show_timestamp [Boolean] whether to show timestamps (default: false)
|
33
|
-
# @param show_level [Boolean] whether to show log levels (default: false)
|
34
|
-
# @param formatter_options [Hash] additional formatter options
|
35
|
-
def initialize(formatter: :console, show_timestamp: false, show_level: false, **formatter_options)
|
36
|
-
@format = formatter.to_sym
|
37
|
-
|
38
|
-
# Build configuration for UnifiedFileSink
|
39
|
-
configuration = {
|
40
|
-
file: $stdout,
|
41
|
-
format: @format,
|
42
|
-
formatter_options: {
|
43
|
-
show_timestamp: show_timestamp,
|
44
|
-
show_level: show_level,
|
45
|
-
}.merge(formatter_options),
|
46
|
-
}
|
47
|
-
|
48
|
-
super(configurations: [configuration])
|
49
|
-
end
|
50
|
-
|
51
|
-
# Get sink configuration
|
52
|
-
#
|
53
|
-
# @return [Hash] sink configuration
|
54
|
-
def config
|
55
|
-
{
|
56
|
-
name: self.class.name.split("::").last,
|
57
|
-
format: @format,
|
58
|
-
colors_enabled: true,
|
59
|
-
unified_sink: true,
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
# Check if this is a console sink (for compatibility)
|
64
|
-
#
|
65
|
-
# @return [Boolean] always true for Console sink
|
66
|
-
def console?
|
67
|
-
true
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "unified_file_sink"
|
4
|
+
|
5
|
+
module Makit
|
6
|
+
module Logging
|
7
|
+
module Sinks
|
8
|
+
# Console sink for clean, colored log output
|
9
|
+
#
|
10
|
+
# This is a thin wrapper around UnifiedFileSink that provides a simple
|
11
|
+
# API for console output. It maintains backward compatibility while
|
12
|
+
# leveraging the unified logging architecture.
|
13
|
+
#
|
14
|
+
# @example Basic usage
|
15
|
+
# console = Console.new
|
16
|
+
# logger = Logger.new(sinks: [console])
|
17
|
+
# logger.info("Processing started")
|
18
|
+
# # Shows: → Processing started
|
19
|
+
#
|
20
|
+
# @example With custom formatter options
|
21
|
+
# console = Console.new(show_timestamp: true, show_level: true)
|
22
|
+
#
|
23
|
+
# @example With custom formatter
|
24
|
+
# console = Console.new(formatter: :text)
|
25
|
+
class Console < UnifiedFileSink
|
26
|
+
# @return [Symbol] the format being used
|
27
|
+
attr_reader :format
|
28
|
+
|
29
|
+
# Initialize console sink
|
30
|
+
#
|
31
|
+
# @param formatter [Symbol, String] formatter name (default: :console)
|
32
|
+
# @param show_timestamp [Boolean] whether to show timestamps (default: false)
|
33
|
+
# @param show_level [Boolean] whether to show log levels (default: false)
|
34
|
+
# @param formatter_options [Hash] additional formatter options
|
35
|
+
def initialize(formatter: :console, show_timestamp: false, show_level: false, **formatter_options)
|
36
|
+
@format = formatter.to_sym
|
37
|
+
|
38
|
+
# Build configuration for UnifiedFileSink
|
39
|
+
configuration = {
|
40
|
+
file: $stdout,
|
41
|
+
format: @format,
|
42
|
+
formatter_options: {
|
43
|
+
show_timestamp: show_timestamp,
|
44
|
+
show_level: show_level,
|
45
|
+
}.merge(formatter_options),
|
46
|
+
}
|
47
|
+
|
48
|
+
super(configurations: [configuration])
|
49
|
+
end
|
50
|
+
|
51
|
+
# Get sink configuration
|
52
|
+
#
|
53
|
+
# @return [Hash] sink configuration
|
54
|
+
def config
|
55
|
+
{
|
56
|
+
name: self.class.name.split("::").last,
|
57
|
+
format: @format,
|
58
|
+
colors_enabled: true,
|
59
|
+
unified_sink: true,
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
# Check if this is a console sink (for compatibility)
|
64
|
+
#
|
65
|
+
# @return [Boolean] always true for Console sink
|
66
|
+
def console?
|
67
|
+
true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,92 +1,92 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "unified_file_sink"
|
4
|
-
|
5
|
-
module Makit
|
6
|
-
module Logging
|
7
|
-
module Sinks
|
8
|
-
# File sink for writing log entries to files
|
9
|
-
#
|
10
|
-
# This sink is a thin wrapper around UnifiedFileSink that provides
|
11
|
-
# a simpler API for single-file logging. It maintains backward compatibility
|
12
|
-
# with the original FileSink interface while leveraging the more robust
|
13
|
-
# UnifiedFileSink implementation.
|
14
|
-
#
|
15
|
-
# @example Basic usage with default JSON formatter
|
16
|
-
# file_sink = FileSink.new(log_file: "makit.log")
|
17
|
-
# logger = Logger.new(sinks: [file_sink])
|
18
|
-
# logger.info("Processing started")
|
19
|
-
#
|
20
|
-
# @example Using built-in formatters
|
21
|
-
# file_sink = FileSink.new(
|
22
|
-
# log_file: "makit.log",
|
23
|
-
# formatter: :text
|
24
|
-
# )
|
25
|
-
#
|
26
|
-
# @example Using custom formatter options
|
27
|
-
# file_sink = FileSink.new(
|
28
|
-
# log_file: "makit.log",
|
29
|
-
# formatter: :json,
|
30
|
-
# include_context: true,
|
31
|
-
# include_metadata: true
|
32
|
-
# )
|
33
|
-
class FileSink < Base
|
34
|
-
# @return [String] path to the log file
|
35
|
-
attr_reader :log_file
|
36
|
-
# @return [Symbol] the formatter format name
|
37
|
-
attr_reader :formatter
|
38
|
-
# @return [Boolean] whether to append to existing file (true) or overwrite (false)
|
39
|
-
attr_reader :append
|
40
|
-
# @return [UnifiedFileSink] the underlying unified sink
|
41
|
-
attr_reader :unified_sink
|
42
|
-
|
43
|
-
# Initialize file sink
|
44
|
-
#
|
45
|
-
# @param log_file [String] path to the log file
|
46
|
-
# @param formatter [Symbol, String] formatter format name
|
47
|
-
# @param append [Boolean] whether to append to existing file (true) or overwrite (false)
|
48
|
-
# @param include_context [Boolean] whether to include context in formatted output
|
49
|
-
# @param include_metadata [Boolean] whether to include metadata in formatted output
|
50
|
-
# @param show_timestamp [Boolean] whether to show timestamp in formatted output
|
51
|
-
# @param show_level [Boolean] whether to show log level in formatted output
|
52
|
-
def initialize(log_file: "makit.log", formatter: :json, append: true, **formatter_options)
|
53
|
-
@log_file = log_file
|
54
|
-
@formatter = formatter.to_sym
|
55
|
-
@append = append
|
56
|
-
|
57
|
-
# Create unified sink configuration
|
58
|
-
config = {
|
59
|
-
file: @log_file,
|
60
|
-
format: @formatter,
|
61
|
-
append: @append,
|
62
|
-
}.merge(formatter_options)
|
63
|
-
|
64
|
-
@unified_sink = UnifiedFileSink.new(configurations: [config])
|
65
|
-
end
|
66
|
-
|
67
|
-
# Execute sink logic to write log entry to file
|
68
|
-
#
|
69
|
-
# @param log_request [LogRequest] the log request to process
|
70
|
-
# @yield [LogRequest] yields the processed log request to the next sink
|
71
|
-
# @yieldreturn [LogRequest] the processed log request
|
72
|
-
# @return [LogRequest] the final processed log request
|
73
|
-
def call(log_request, &block)
|
74
|
-
@unified_sink.call(log_request, &block)
|
75
|
-
end
|
76
|
-
|
77
|
-
# Get sink configuration
|
78
|
-
#
|
79
|
-
# @return [Hash] sink configuration
|
80
|
-
def config
|
81
|
-
{
|
82
|
-
name: self.class.name.split("::").last,
|
83
|
-
log_file: @log_file,
|
84
|
-
formatter: @formatter,
|
85
|
-
append: @append,
|
86
|
-
unified_config: @unified_sink.config,
|
87
|
-
}
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "unified_file_sink"
|
4
|
+
|
5
|
+
module Makit
|
6
|
+
module Logging
|
7
|
+
module Sinks
|
8
|
+
# File sink for writing log entries to files
|
9
|
+
#
|
10
|
+
# This sink is a thin wrapper around UnifiedFileSink that provides
|
11
|
+
# a simpler API for single-file logging. It maintains backward compatibility
|
12
|
+
# with the original FileSink interface while leveraging the more robust
|
13
|
+
# UnifiedFileSink implementation.
|
14
|
+
#
|
15
|
+
# @example Basic usage with default JSON formatter
|
16
|
+
# file_sink = FileSink.new(log_file: "makit.log")
|
17
|
+
# logger = Logger.new(sinks: [file_sink])
|
18
|
+
# logger.info("Processing started")
|
19
|
+
#
|
20
|
+
# @example Using built-in formatters
|
21
|
+
# file_sink = FileSink.new(
|
22
|
+
# log_file: "makit.log",
|
23
|
+
# formatter: :text
|
24
|
+
# )
|
25
|
+
#
|
26
|
+
# @example Using custom formatter options
|
27
|
+
# file_sink = FileSink.new(
|
28
|
+
# log_file: "makit.log",
|
29
|
+
# formatter: :json,
|
30
|
+
# include_context: true,
|
31
|
+
# include_metadata: true
|
32
|
+
# )
|
33
|
+
class FileSink < Base
|
34
|
+
# @return [String] path to the log file
|
35
|
+
attr_reader :log_file
|
36
|
+
# @return [Symbol] the formatter format name
|
37
|
+
attr_reader :formatter
|
38
|
+
# @return [Boolean] whether to append to existing file (true) or overwrite (false)
|
39
|
+
attr_reader :append
|
40
|
+
# @return [UnifiedFileSink] the underlying unified sink
|
41
|
+
attr_reader :unified_sink
|
42
|
+
|
43
|
+
# Initialize file sink
|
44
|
+
#
|
45
|
+
# @param log_file [String] path to the log file
|
46
|
+
# @param formatter [Symbol, String] formatter format name
|
47
|
+
# @param append [Boolean] whether to append to existing file (true) or overwrite (false)
|
48
|
+
# @param include_context [Boolean] whether to include context in formatted output
|
49
|
+
# @param include_metadata [Boolean] whether to include metadata in formatted output
|
50
|
+
# @param show_timestamp [Boolean] whether to show timestamp in formatted output
|
51
|
+
# @param show_level [Boolean] whether to show log level in formatted output
|
52
|
+
def initialize(log_file: "makit.log", formatter: :json, append: true, **formatter_options)
|
53
|
+
@log_file = log_file
|
54
|
+
@formatter = formatter.to_sym
|
55
|
+
@append = append
|
56
|
+
|
57
|
+
# Create unified sink configuration
|
58
|
+
config = {
|
59
|
+
file: @log_file,
|
60
|
+
format: @formatter,
|
61
|
+
append: @append,
|
62
|
+
}.merge(formatter_options)
|
63
|
+
|
64
|
+
@unified_sink = UnifiedFileSink.new(configurations: [config])
|
65
|
+
end
|
66
|
+
|
67
|
+
# Execute sink logic to write log entry to file
|
68
|
+
#
|
69
|
+
# @param log_request [LogRequest] the log request to process
|
70
|
+
# @yield [LogRequest] yields the processed log request to the next sink
|
71
|
+
# @yieldreturn [LogRequest] the processed log request
|
72
|
+
# @return [LogRequest] the final processed log request
|
73
|
+
def call(log_request, &block)
|
74
|
+
@unified_sink.call(log_request, &block)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Get sink configuration
|
78
|
+
#
|
79
|
+
# @return [Hash] sink configuration
|
80
|
+
def config
|
81
|
+
{
|
82
|
+
name: self.class.name.split("::").last,
|
83
|
+
log_file: @log_file,
|
84
|
+
formatter: @formatter,
|
85
|
+
append: @append,
|
86
|
+
unified_config: @unified_sink.config,
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|