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
@@ -1,243 +1,243 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "base"
|
4
|
-
|
5
|
-
module Makit
|
6
|
-
module Commands
|
7
|
-
module Middleware
|
8
|
-
# Unified logging middleware that consolidates all command logging functionality
|
9
|
-
#
|
10
|
-
# This middleware replaces the need for multiple separate logging middleware
|
11
|
-
# by providing a single, comprehensive logging solution that handles console
|
12
|
-
# display, file logging, and structured logging through the Makit::Logging system.
|
13
|
-
#
|
14
|
-
# @example Basic usage
|
15
|
-
# logger = UnifiedLogger.new
|
16
|
-
# runner = Runner.new(middleware: [logger])
|
17
|
-
# result = runner.execute("git --version")
|
18
|
-
#
|
19
|
-
# @example With custom logger configuration
|
20
|
-
# custom_logger = Makit::Logging::Logger.new(
|
21
|
-
# sinks: [
|
22
|
-
# Makit::Logging::Sinks::Console.new,
|
23
|
-
# Makit::Logging::Sinks::FileSink.new(log_file: "artifacts/commands.log")
|
24
|
-
# ]
|
25
|
-
# )
|
26
|
-
# logger = UnifiedLogger.new(logger: custom_logger)
|
27
|
-
# runner = Runner.new(middleware: [logger])
|
28
|
-
class UnifiedLogger < Base
|
29
|
-
# @!attribute [r] logger
|
30
|
-
# @return [Makit::Logging::Logger] the logging instance
|
31
|
-
attr_reader :logger
|
32
|
-
|
33
|
-
# Initialize unified logging middleware.
|
34
|
-
#
|
35
|
-
# @param logger [Makit::Logging::Logger, nil] custom logger instance
|
36
|
-
# @param log_to_console [Boolean] whether to log to console
|
37
|
-
# @param log_to_file [Boolean] whether to log to file
|
38
|
-
# @param log_performance [Boolean] whether to log performance metrics
|
39
|
-
# @param log_output [Boolean] whether to log command output
|
40
|
-
def initialize(logger: nil, log_to_console: true, log_to_file: true, log_performance: true, log_output: false)
|
41
|
-
@logger = logger || create_default_logger(log_to_console, log_to_file)
|
42
|
-
@log_performance = log_performance
|
43
|
-
@log_output = log_output
|
44
|
-
end
|
45
|
-
|
46
|
-
# Execute command with unified logging.
|
47
|
-
#
|
48
|
-
# @param request [Request] command request to execute
|
49
|
-
# @yield [Request] yields request to next middleware
|
50
|
-
# @return [Result] execution result
|
51
|
-
def call(request, &block)
|
52
|
-
command_id = generate_command_id
|
53
|
-
start_time = Time.now
|
54
|
-
|
55
|
-
# Log command start
|
56
|
-
log_command_start(request, command_id)
|
57
|
-
|
58
|
-
begin
|
59
|
-
# Execute the command
|
60
|
-
result = block.call(request)
|
61
|
-
duration = Time.now - start_time
|
62
|
-
|
63
|
-
# Log command completion
|
64
|
-
log_command_completion(request, result, duration, command_id)
|
65
|
-
|
66
|
-
result
|
67
|
-
rescue => error
|
68
|
-
duration = Time.now - start_time
|
69
|
-
|
70
|
-
# Log command error
|
71
|
-
log_command_error(request, error, duration, command_id)
|
72
|
-
|
73
|
-
raise
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Check if this middleware applies to the given request.
|
78
|
-
#
|
79
|
-
# @param request [Request] command request
|
80
|
-
# @return [Boolean] true if middleware applies
|
81
|
-
def applicable?(request)
|
82
|
-
true
|
83
|
-
end
|
84
|
-
|
85
|
-
# Get middleware configuration.
|
86
|
-
#
|
87
|
-
# @return [Hash] middleware configuration
|
88
|
-
def config
|
89
|
-
{
|
90
|
-
name: "UnifiedLogger",
|
91
|
-
description: "Unified logging for command execution with console and file output",
|
92
|
-
log_performance: @log_performance,
|
93
|
-
log_output: @log_output,
|
94
|
-
logger_class: @logger.class.name,
|
95
|
-
}
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
|
100
|
-
# Create default logger with console and file output
|
101
|
-
#
|
102
|
-
# @param log_to_console [Boolean] whether to log to console
|
103
|
-
# @param log_to_file [Boolean] whether to log to file
|
104
|
-
# @return [Makit::Logging::Logger] configured logger
|
105
|
-
def create_default_logger(log_to_console, log_to_file)
|
106
|
-
sinks = []
|
107
|
-
|
108
|
-
if log_to_console
|
109
|
-
sinks << Makit::Logging::Sinks::Console.new
|
110
|
-
end
|
111
|
-
|
112
|
-
if log_to_file
|
113
|
-
sinks << Makit::Logging::Sinks::FileSink.new(
|
114
|
-
log_file: "artifacts/commands.log",
|
115
|
-
formatter: :json,
|
116
|
-
include_metadata: true,
|
117
|
-
)
|
118
|
-
end
|
119
|
-
|
120
|
-
Makit::Logging::Logger.new(sinks: sinks)
|
121
|
-
end
|
122
|
-
|
123
|
-
# Log command execution start.
|
124
|
-
#
|
125
|
-
# @param request [Request] command request
|
126
|
-
# @param command_id [String] unique command identifier
|
127
|
-
def log_command_start(request, command_id)
|
128
|
-
@logger.info("Command execution started", {
|
129
|
-
command_id: command_id,
|
130
|
-
command: request.command,
|
131
|
-
arguments: request.arguments,
|
132
|
-
working_directory: request.directory,
|
133
|
-
timeout: request.timeout,
|
134
|
-
environment: request.environment&.keys || [],
|
135
|
-
})
|
136
|
-
end
|
137
|
-
|
138
|
-
# Log command execution completion.
|
139
|
-
#
|
140
|
-
# @param request [Request] command request
|
141
|
-
# @param result [Result] execution result
|
142
|
-
# @param duration [Float] execution duration
|
143
|
-
# @param command_id [String] unique command identifier
|
144
|
-
def log_command_completion(request, result, duration, command_id)
|
145
|
-
log_data = {
|
146
|
-
command_id: command_id,
|
147
|
-
command: request.command,
|
148
|
-
arguments: request.arguments,
|
149
|
-
success: result.success?,
|
150
|
-
exit_code: result.exit_code,
|
151
|
-
duration: duration,
|
152
|
-
working_directory: request.directory,
|
153
|
-
}
|
154
|
-
|
155
|
-
# Add performance metrics if enabled
|
156
|
-
if @log_performance
|
157
|
-
log_data.merge!(
|
158
|
-
memory_usage: get_memory_usage,
|
159
|
-
timestamp: Time.now.iso8601,
|
160
|
-
)
|
161
|
-
end
|
162
|
-
|
163
|
-
# Add output if enabled and present
|
164
|
-
if @log_output
|
165
|
-
log_data[:stdout_lines] = result.stdout&.split("\n")&.length || 0
|
166
|
-
log_data[:stderr_lines] = result.stderr&.split("\n")&.length || 0
|
167
|
-
log_data[:stdout] = result.stdout if result.stdout && !result.stdout.empty?
|
168
|
-
log_data[:stderr] = result.stderr if result.stderr && !result.stderr.empty?
|
169
|
-
end
|
170
|
-
|
171
|
-
# Log at appropriate level based on success
|
172
|
-
if result.success?
|
173
|
-
@logger.success("Command completed successfully", log_data)
|
174
|
-
else
|
175
|
-
@logger.error("Command completed with errors", log_data)
|
176
|
-
end
|
177
|
-
|
178
|
-
# Log slow commands
|
179
|
-
if @log_performance && duration > 1.0
|
180
|
-
@logger.warn("Slow command detected",
|
181
|
-
command_id: command_id,
|
182
|
-
command: request.command,
|
183
|
-
duration: duration)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
# Log command execution error.
|
188
|
-
#
|
189
|
-
# @param request [Request] command request
|
190
|
-
# @param error [Exception] execution error
|
191
|
-
# @param duration [Float] execution duration
|
192
|
-
# @param command_id [String] unique command identifier
|
193
|
-
def log_command_error(request, error, duration, command_id)
|
194
|
-
@logger.error("Command execution failed", {
|
195
|
-
command_id: command_id,
|
196
|
-
command: request.command,
|
197
|
-
arguments: request.arguments,
|
198
|
-
working_directory: request.directory,
|
199
|
-
error_class: error.class.name,
|
200
|
-
error_message: error.message,
|
201
|
-
duration: duration,
|
202
|
-
backtrace: error.backtrace&.first(5),
|
203
|
-
})
|
204
|
-
end
|
205
|
-
|
206
|
-
# Generate a unique command identifier.
|
207
|
-
#
|
208
|
-
# @return [String] unique command ID
|
209
|
-
def generate_command_id
|
210
|
-
"#{::Process.pid}-#{Time.now.to_f}-#{rand(1000)}"
|
211
|
-
end
|
212
|
-
|
213
|
-
# Get current memory usage (if available).
|
214
|
-
#
|
215
|
-
# @return [String, nil] memory usage string or nil if unavailable
|
216
|
-
def get_memory_usage
|
217
|
-
# Try to get memory usage on different platforms
|
218
|
-
if RUBY_PLATFORM.match?(/mswin|mingw/)
|
219
|
-
# Windows - try to get memory usage
|
220
|
-
begin
|
221
|
-
"Unknown"
|
222
|
-
rescue
|
223
|
-
nil
|
224
|
-
end
|
225
|
-
else
|
226
|
-
# Unix-like systems
|
227
|
-
begin
|
228
|
-
# Try to get memory usage from /proc/self/status
|
229
|
-
if File.exist?("/proc/self/status")
|
230
|
-
status = File.read("/proc/self/status")
|
231
|
-
if match = status.match(/VmRSS:\s+(\d+)\s+kB/)
|
232
|
-
"#{match[1].to_i / 1024}MB"
|
233
|
-
end
|
234
|
-
end
|
235
|
-
rescue
|
236
|
-
nil
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Makit
|
6
|
+
module Commands
|
7
|
+
module Middleware
|
8
|
+
# Unified logging middleware that consolidates all command logging functionality
|
9
|
+
#
|
10
|
+
# This middleware replaces the need for multiple separate logging middleware
|
11
|
+
# by providing a single, comprehensive logging solution that handles console
|
12
|
+
# display, file logging, and structured logging through the Makit::Logging system.
|
13
|
+
#
|
14
|
+
# @example Basic usage
|
15
|
+
# logger = UnifiedLogger.new
|
16
|
+
# runner = Runner.new(middleware: [logger])
|
17
|
+
# result = runner.execute("git --version")
|
18
|
+
#
|
19
|
+
# @example With custom logger configuration
|
20
|
+
# custom_logger = Makit::Logging::Logger.new(
|
21
|
+
# sinks: [
|
22
|
+
# Makit::Logging::Sinks::Console.new,
|
23
|
+
# Makit::Logging::Sinks::FileSink.new(log_file: "artifacts/commands.log")
|
24
|
+
# ]
|
25
|
+
# )
|
26
|
+
# logger = UnifiedLogger.new(logger: custom_logger)
|
27
|
+
# runner = Runner.new(middleware: [logger])
|
28
|
+
class UnifiedLogger < Base
|
29
|
+
# @!attribute [r] logger
|
30
|
+
# @return [Makit::Logging::Logger] the logging instance
|
31
|
+
attr_reader :logger
|
32
|
+
|
33
|
+
# Initialize unified logging middleware.
|
34
|
+
#
|
35
|
+
# @param logger [Makit::Logging::Logger, nil] custom logger instance
|
36
|
+
# @param log_to_console [Boolean] whether to log to console
|
37
|
+
# @param log_to_file [Boolean] whether to log to file
|
38
|
+
# @param log_performance [Boolean] whether to log performance metrics
|
39
|
+
# @param log_output [Boolean] whether to log command output
|
40
|
+
def initialize(logger: nil, log_to_console: true, log_to_file: true, log_performance: true, log_output: false)
|
41
|
+
@logger = logger || create_default_logger(log_to_console, log_to_file)
|
42
|
+
@log_performance = log_performance
|
43
|
+
@log_output = log_output
|
44
|
+
end
|
45
|
+
|
46
|
+
# Execute command with unified logging.
|
47
|
+
#
|
48
|
+
# @param request [Request] command request to execute
|
49
|
+
# @yield [Request] yields request to next middleware
|
50
|
+
# @return [Result] execution result
|
51
|
+
def call(request, &block)
|
52
|
+
command_id = generate_command_id
|
53
|
+
start_time = Time.now
|
54
|
+
|
55
|
+
# Log command start
|
56
|
+
log_command_start(request, command_id)
|
57
|
+
|
58
|
+
begin
|
59
|
+
# Execute the command
|
60
|
+
result = block.call(request)
|
61
|
+
duration = Time.now - start_time
|
62
|
+
|
63
|
+
# Log command completion
|
64
|
+
log_command_completion(request, result, duration, command_id)
|
65
|
+
|
66
|
+
result
|
67
|
+
rescue => error
|
68
|
+
duration = Time.now - start_time
|
69
|
+
|
70
|
+
# Log command error
|
71
|
+
log_command_error(request, error, duration, command_id)
|
72
|
+
|
73
|
+
raise
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Check if this middleware applies to the given request.
|
78
|
+
#
|
79
|
+
# @param request [Request] command request
|
80
|
+
# @return [Boolean] true if middleware applies
|
81
|
+
def applicable?(request)
|
82
|
+
true
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get middleware configuration.
|
86
|
+
#
|
87
|
+
# @return [Hash] middleware configuration
|
88
|
+
def config
|
89
|
+
{
|
90
|
+
name: "UnifiedLogger",
|
91
|
+
description: "Unified logging for command execution with console and file output",
|
92
|
+
log_performance: @log_performance,
|
93
|
+
log_output: @log_output,
|
94
|
+
logger_class: @logger.class.name,
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
# Create default logger with console and file output
|
101
|
+
#
|
102
|
+
# @param log_to_console [Boolean] whether to log to console
|
103
|
+
# @param log_to_file [Boolean] whether to log to file
|
104
|
+
# @return [Makit::Logging::Logger] configured logger
|
105
|
+
def create_default_logger(log_to_console, log_to_file)
|
106
|
+
sinks = []
|
107
|
+
|
108
|
+
if log_to_console
|
109
|
+
sinks << Makit::Logging::Sinks::Console.new
|
110
|
+
end
|
111
|
+
|
112
|
+
if log_to_file
|
113
|
+
sinks << Makit::Logging::Sinks::FileSink.new(
|
114
|
+
log_file: "artifacts/commands.log",
|
115
|
+
formatter: :json,
|
116
|
+
include_metadata: true,
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
Makit::Logging::Logger.new(sinks: sinks)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Log command execution start.
|
124
|
+
#
|
125
|
+
# @param request [Request] command request
|
126
|
+
# @param command_id [String] unique command identifier
|
127
|
+
def log_command_start(request, command_id)
|
128
|
+
@logger.info("Command execution started", {
|
129
|
+
command_id: command_id,
|
130
|
+
command: request.command,
|
131
|
+
arguments: request.arguments,
|
132
|
+
working_directory: request.directory,
|
133
|
+
timeout: request.timeout,
|
134
|
+
environment: request.environment&.keys || [],
|
135
|
+
})
|
136
|
+
end
|
137
|
+
|
138
|
+
# Log command execution completion.
|
139
|
+
#
|
140
|
+
# @param request [Request] command request
|
141
|
+
# @param result [Result] execution result
|
142
|
+
# @param duration [Float] execution duration
|
143
|
+
# @param command_id [String] unique command identifier
|
144
|
+
def log_command_completion(request, result, duration, command_id)
|
145
|
+
log_data = {
|
146
|
+
command_id: command_id,
|
147
|
+
command: request.command,
|
148
|
+
arguments: request.arguments,
|
149
|
+
success: result.success?,
|
150
|
+
exit_code: result.exit_code,
|
151
|
+
duration: duration,
|
152
|
+
working_directory: request.directory,
|
153
|
+
}
|
154
|
+
|
155
|
+
# Add performance metrics if enabled
|
156
|
+
if @log_performance
|
157
|
+
log_data.merge!(
|
158
|
+
memory_usage: get_memory_usage,
|
159
|
+
timestamp: Time.now.iso8601,
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Add output if enabled and present
|
164
|
+
if @log_output
|
165
|
+
log_data[:stdout_lines] = result.stdout&.split("\n")&.length || 0
|
166
|
+
log_data[:stderr_lines] = result.stderr&.split("\n")&.length || 0
|
167
|
+
log_data[:stdout] = result.stdout if result.stdout && !result.stdout.empty?
|
168
|
+
log_data[:stderr] = result.stderr if result.stderr && !result.stderr.empty?
|
169
|
+
end
|
170
|
+
|
171
|
+
# Log at appropriate level based on success
|
172
|
+
if result.success?
|
173
|
+
@logger.success("Command completed successfully", log_data)
|
174
|
+
else
|
175
|
+
@logger.error("Command completed with errors", log_data)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Log slow commands
|
179
|
+
if @log_performance && duration > 1.0
|
180
|
+
@logger.warn("Slow command detected",
|
181
|
+
command_id: command_id,
|
182
|
+
command: request.command,
|
183
|
+
duration: duration)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Log command execution error.
|
188
|
+
#
|
189
|
+
# @param request [Request] command request
|
190
|
+
# @param error [Exception] execution error
|
191
|
+
# @param duration [Float] execution duration
|
192
|
+
# @param command_id [String] unique command identifier
|
193
|
+
def log_command_error(request, error, duration, command_id)
|
194
|
+
@logger.error("Command execution failed", {
|
195
|
+
command_id: command_id,
|
196
|
+
command: request.command,
|
197
|
+
arguments: request.arguments,
|
198
|
+
working_directory: request.directory,
|
199
|
+
error_class: error.class.name,
|
200
|
+
error_message: error.message,
|
201
|
+
duration: duration,
|
202
|
+
backtrace: error.backtrace&.first(5),
|
203
|
+
})
|
204
|
+
end
|
205
|
+
|
206
|
+
# Generate a unique command identifier.
|
207
|
+
#
|
208
|
+
# @return [String] unique command ID
|
209
|
+
def generate_command_id
|
210
|
+
"#{::Process.pid}-#{Time.now.to_f}-#{rand(1000)}"
|
211
|
+
end
|
212
|
+
|
213
|
+
# Get current memory usage (if available).
|
214
|
+
#
|
215
|
+
# @return [String, nil] memory usage string or nil if unavailable
|
216
|
+
def get_memory_usage
|
217
|
+
# Try to get memory usage on different platforms
|
218
|
+
if RUBY_PLATFORM.match?(/mswin|mingw/)
|
219
|
+
# Windows - try to get memory usage
|
220
|
+
begin
|
221
|
+
"Unknown"
|
222
|
+
rescue
|
223
|
+
nil
|
224
|
+
end
|
225
|
+
else
|
226
|
+
# Unix-like systems
|
227
|
+
begin
|
228
|
+
# Try to get memory usage from /proc/self/status
|
229
|
+
if File.exist?("/proc/self/status")
|
230
|
+
status = File.read("/proc/self/status")
|
231
|
+
if match = status.match(/VmRSS:\s+(\d+)\s+kB/)
|
232
|
+
"#{match[1].to_i / 1024}MB"
|
233
|
+
end
|
234
|
+
end
|
235
|
+
rescue
|
236
|
+
nil
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|