makit 0.0.99 → 0.0.111

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.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +41 -0
  3. data/exe/makit +5 -0
  4. data/lib/makit/apache.rb +7 -11
  5. data/lib/makit/cli/build_commands.rb +500 -0
  6. data/lib/makit/cli/generators/base_generator.rb +74 -0
  7. data/lib/makit/cli/generators/dotnet_generator.rb +50 -0
  8. data/lib/makit/cli/generators/generator_factory.rb +49 -0
  9. data/lib/makit/cli/generators/node_generator.rb +50 -0
  10. data/lib/makit/cli/generators/ruby_generator.rb +77 -0
  11. data/lib/makit/cli/generators/rust_generator.rb +50 -0
  12. data/lib/makit/cli/generators/templates/dotnet_templates.rb +167 -0
  13. data/lib/makit/cli/generators/templates/node_templates.rb +161 -0
  14. data/lib/makit/cli/generators/templates/ruby/gemfile.rb +26 -0
  15. data/lib/makit/cli/generators/templates/ruby/gemspec.rb +40 -0
  16. data/lib/makit/cli/generators/templates/ruby/main_lib.rb +33 -0
  17. data/lib/makit/cli/generators/templates/ruby/rakefile.rb +35 -0
  18. data/lib/makit/cli/generators/templates/ruby/readme.rb +63 -0
  19. data/lib/makit/cli/generators/templates/ruby/test.rb +39 -0
  20. data/lib/makit/cli/generators/templates/ruby/test_helper.rb +29 -0
  21. data/lib/makit/cli/generators/templates/ruby/version.rb +29 -0
  22. data/lib/makit/cli/generators/templates/rust_templates.rb +128 -0
  23. data/lib/makit/cli/main.rb +48 -19
  24. data/lib/makit/cli/project_commands.rb +868 -0
  25. data/lib/makit/cli/repository_commands.rb +661 -0
  26. data/lib/makit/cli/utility_commands.rb +521 -0
  27. data/lib/makit/command_runner.rb +187 -128
  28. data/lib/makit/commands/compatibility.rb +365 -0
  29. data/lib/makit/commands/factory.rb +359 -0
  30. data/lib/makit/commands/middleware/base.rb +73 -0
  31. data/lib/makit/commands/middleware/cache.rb +248 -0
  32. data/lib/makit/commands/middleware/command_logger.rb +323 -0
  33. data/lib/makit/commands/middleware/unified_logger.rb +243 -0
  34. data/lib/makit/commands/middleware/validator.rb +269 -0
  35. data/lib/makit/commands/request.rb +254 -0
  36. data/lib/makit/commands/result.rb +323 -0
  37. data/lib/makit/commands/runner.rb +317 -0
  38. data/lib/makit/commands/strategies/base.rb +160 -0
  39. data/lib/makit/commands/strategies/synchronous.rb +134 -0
  40. data/lib/makit/commands.rb +24 -3
  41. data/lib/makit/configuration/gitlab_helper.rb +60 -0
  42. data/lib/makit/configuration/project.rb +127 -0
  43. data/lib/makit/configuration/rakefile_helper.rb +43 -0
  44. data/lib/makit/configuration/step.rb +34 -0
  45. data/lib/makit/configuration.rb +14 -0
  46. data/lib/makit/content/default_gitignore.rb +4 -2
  47. data/lib/makit/content/default_rakefile.rb +4 -2
  48. data/lib/makit/content/gem_rakefile.rb +4 -2
  49. data/lib/makit/context.rb +1 -0
  50. data/lib/makit/data.rb +9 -10
  51. data/lib/makit/directories.rb +48 -52
  52. data/lib/makit/directory.rb +38 -52
  53. data/lib/makit/docs/files.rb +5 -10
  54. data/lib/makit/docs/rake.rb +16 -20
  55. data/lib/makit/dotnet/cli.rb +65 -0
  56. data/lib/makit/dotnet/project.rb +153 -0
  57. data/lib/makit/dotnet/solution.rb +38 -0
  58. data/lib/makit/dotnet/solution_classlib.rb +239 -0
  59. data/lib/makit/dotnet/solution_console.rb +264 -0
  60. data/lib/makit/dotnet/solution_maui.rb +354 -0
  61. data/lib/makit/dotnet/solution_wasm.rb +275 -0
  62. data/lib/makit/dotnet/solution_wpf.rb +304 -0
  63. data/lib/makit/dotnet.rb +54 -171
  64. data/lib/makit/email.rb +46 -17
  65. data/lib/makit/environment.rb +22 -19
  66. data/lib/makit/examples/runner.rb +370 -0
  67. data/lib/makit/exceptions.rb +45 -0
  68. data/lib/makit/fileinfo.rb +3 -5
  69. data/lib/makit/files.rb +12 -16
  70. data/lib/makit/gems.rb +40 -39
  71. data/lib/makit/git/cli.rb +54 -0
  72. data/lib/makit/git/repository.rb +90 -0
  73. data/lib/makit/git.rb +44 -91
  74. data/lib/makit/gitlab_runner.rb +0 -1
  75. data/lib/makit/humanize.rb +31 -23
  76. data/lib/makit/indexer.rb +15 -24
  77. data/lib/makit/logging/configuration.rb +305 -0
  78. data/lib/makit/logging/format_registry.rb +84 -0
  79. data/lib/makit/logging/formatters/base.rb +39 -0
  80. data/lib/makit/logging/formatters/console_formatter.rb +127 -0
  81. data/lib/makit/logging/formatters/json_formatter.rb +65 -0
  82. data/lib/makit/logging/formatters/plain_text_formatter.rb +71 -0
  83. data/lib/makit/logging/formatters/text_formatter.rb +64 -0
  84. data/lib/makit/logging/log_request.rb +115 -0
  85. data/lib/makit/logging/logger.rb +159 -0
  86. data/lib/makit/logging/sinks/base.rb +91 -0
  87. data/lib/makit/logging/sinks/console.rb +72 -0
  88. data/lib/makit/logging/sinks/file_sink.rb +92 -0
  89. data/lib/makit/logging/sinks/structured.rb +129 -0
  90. data/lib/makit/logging/sinks/unified_file_sink.rb +303 -0
  91. data/lib/makit/logging.rb +452 -37
  92. data/lib/makit/markdown.rb +18 -18
  93. data/lib/makit/mp/basic_object_mp.rb +5 -4
  94. data/lib/makit/mp/command_mp.rb +5 -5
  95. data/lib/makit/mp/command_request.mp.rb +3 -2
  96. data/lib/makit/mp/project_mp.rb +85 -96
  97. data/lib/makit/mp/string_mp.rb +245 -73
  98. data/lib/makit/nuget.rb +27 -25
  99. data/lib/makit/port.rb +25 -27
  100. data/lib/makit/process.rb +127 -29
  101. data/lib/makit/protoc.rb +27 -24
  102. data/lib/makit/rake/cli.rb +196 -0
  103. data/lib/makit/rake.rb +6 -6
  104. data/lib/makit/ruby/cli.rb +185 -0
  105. data/lib/makit/ruby.rb +25 -0
  106. data/lib/makit/secrets.rb +18 -18
  107. data/lib/makit/serializer.rb +29 -27
  108. data/lib/makit/services/builder.rb +186 -0
  109. data/lib/makit/services/error_handler.rb +226 -0
  110. data/lib/makit/services/repository_manager.rb +229 -0
  111. data/lib/makit/services/validator.rb +112 -0
  112. data/lib/makit/setup/classlib.rb +53 -0
  113. data/lib/makit/setup/gem.rb +250 -0
  114. data/lib/makit/setup/runner.rb +40 -0
  115. data/lib/makit/show.rb +16 -16
  116. data/lib/makit/storage.rb +32 -37
  117. data/lib/makit/symbols.rb +12 -0
  118. data/lib/makit/task_hooks.rb +125 -0
  119. data/lib/makit/task_info.rb +63 -21
  120. data/lib/makit/tasks/at_exit.rb +13 -0
  121. data/lib/makit/tasks/build.rb +18 -0
  122. data/lib/makit/tasks/clean.rb +11 -0
  123. data/lib/makit/tasks/hook_manager.rb +239 -0
  124. data/lib/makit/tasks/init.rb +47 -0
  125. data/lib/makit/tasks/integrate.rb +15 -0
  126. data/lib/makit/tasks/pull_incoming.rb +12 -0
  127. data/lib/makit/tasks/setup.rb +6 -0
  128. data/lib/makit/tasks/sync.rb +11 -0
  129. data/lib/makit/tasks/task_monkey_patch.rb +79 -0
  130. data/lib/makit/tasks.rb +5 -150
  131. data/lib/makit/test_cache.rb +239 -0
  132. data/lib/makit/v1/makit.v1_pb.rb +34 -35
  133. data/lib/makit/v1/makit.v1_services_pb.rb +2 -0
  134. data/lib/makit/version.rb +1 -57
  135. data/lib/makit/wix.rb +23 -23
  136. data/lib/makit/yaml.rb +18 -6
  137. data/lib/makit.rb +2 -261
  138. metadata +109 -145
  139. data/lib/makit/cli/clean.rb +0 -14
  140. data/lib/makit/cli/clone.rb +0 -59
  141. data/lib/makit/cli/init.rb +0 -38
  142. data/lib/makit/cli/make.rb +0 -54
  143. data/lib/makit/cli/new.rb +0 -37
  144. data/lib/makit/cli/nuget_cache.rb +0 -38
  145. data/lib/makit/cli/pull.rb +0 -31
  146. data/lib/makit/cli/setup.rb +0 -71
  147. data/lib/makit/cli/work.rb +0 -21
  148. data/lib/makit/content/default_gitignore.txt +0 -222
data/lib/makit/logging.rb CHANGED
@@ -3,46 +3,212 @@
3
3
  require "logger"
4
4
  require "colorize"
5
5
  require_relative "symbols"
6
+ require_relative "logging/logger"
7
+ require_relative "logging/log_request"
8
+ require_relative "logging/sinks/base"
9
+ require_relative "logging/sinks/console"
10
+ require_relative "logging/sinks/file_sink"
11
+ require_relative "logging/sinks/structured"
12
+ require_relative "logging/sinks/unified_file_sink"
13
+ require_relative "logging/configuration"
6
14
 
7
15
  # This module provides classes for the Makit gem.
8
16
  module Makit
17
+ # Logging infrastructure for the Makit gem
18
+ #
19
+ # This module provides a comprehensive logging system with multiple formatters,
20
+ # multi-target output capabilities, and configurable log levels. It supports:
21
+ #
22
+ # - Plain text logging (suitable for files)
23
+ # - Colored console output (improved terminal readability)
24
+ # - Structured JSON logging (machine-parsable format)
25
+ # - Multi-target logging (write to multiple destinations simultaneously)
26
+ # - Sink-based output processing (similar to Commands::Runner)
27
+ #
28
+ # @deprecated The legacy MultiLogger, Formatter classes, and create_logger method
29
+ # are deprecated and will be removed in version 0.2.0. Use the new Logger class
30
+ # with sinks instead.
31
+ #
32
+ # @example Basic usage with new architecture (recommended)
33
+ # Makit::Logging.info("Application started")
34
+ # Makit::Logging.success("Build completed")
35
+ # Makit::Logging.error("Something went wrong")
36
+ #
37
+ # @example Custom logger configuration
38
+ # logger = Makit::Logging::Logger.new(
39
+ # sinks: [
40
+ # Makit::Logging::Sinks::Console.new,
41
+ # Makit::Logging::Sinks::FileSink.new(log_file: "custom.log")
42
+ # ]
43
+ # )
44
+ # logger.info("Custom message")
45
+ #
46
+ # @example Legacy usage (deprecated - will be removed in v0.2.0)
47
+ # logger = Makit::Logging::MultiLogger.create_logger
48
+ # logger.info("Application started")
49
+ # logger.error("Something went wrong")
9
50
  module Logging
10
51
  ANSI_COLOR_REGEX = /\e\[[0-9;]*m/
11
52
 
53
+ # Log levels that can be configured
54
+ LOG_LEVELS = {
55
+ debug: ::Logger::DEBUG,
56
+ info: ::Logger::INFO,
57
+ warn: ::Logger::WARN,
58
+ error: ::Logger::ERROR,
59
+ fatal: ::Logger::FATAL,
60
+ }.freeze
61
+
62
+ # Default log level
63
+ DEFAULT_LOG_LEVEL = :info
64
+
65
+ # Get the current log level from environment or use default
66
+ def self.current_log_level
67
+ env_level = ENV["LOG_LEVEL"]&.downcase&.to_sym
68
+ return env_level if env_level && LOG_LEVELS.key?(env_level)
69
+ DEFAULT_LOG_LEVEL
70
+ end
71
+
72
+ # Logs the duration of a rake task to a file
73
+ #
74
+ # This method calculates the elapsed time since the STARTTIME constant was set
75
+ # and appends this information to a log file. Used to track performance of rake tasks.
76
+ #
77
+ # @return [nil]
12
78
  def self.log_rake_duration
13
79
  # use the STARTTIME constant to log the duration of the rake task
14
80
  # to the log/rake.duration.txt file
15
81
  duration = Time.now - STARTTIME
16
- FileUtils.mkdir_p("log") unless Dir.exist?("log")
82
+ FileUtils.mkdir_p("log")
17
83
  File.open("log/rake.duration.txt", "a") do |file|
18
84
  file.puts "Rake task duration: #{duration} seconds"
19
85
  end
20
86
  end
21
87
 
22
- class PlainFormatter < Logger::Formatter
23
- def call(_severity, _time, _progname, msg)
88
+ # Plain text log formatter that strips ANSI color codes
89
+ #
90
+ # This formatter removes color codes from log messages and provides
91
+ # clean, plain text output suitable for file logging or systems
92
+ # that don't support color output.
93
+ #
94
+ # @deprecated This class is deprecated and will be removed in version 0.2.0.
95
+ # Use Makit::Logging::Logger with Makit::Logging::Sinks::FileSink instead.
96
+ class PlainFormatter < ::Logger::Formatter
97
+ # Format a log message as plain text
98
+ #
99
+ # @param severity [String] log level (DEBUG, INFO, WARN, ERROR, FATAL)
100
+ # @param time [Time] timestamp of the log message
101
+ # @param _progname [String] program name (unused)
102
+ # @param msg [String] the log message content
103
+ # @return [String] formatted plain text log entry
104
+ def call(severity, time, _progname, msg)
105
+ warn "Makit::Logging::PlainFormatter is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger with Makit::Logging::Sinks::FileSink instead."
24
106
  stripped_msg = msg.gsub(ANSI_COLOR_REGEX, "") # Remove ANSI color codes
25
- "#{stripped_msg}\n"
107
+ timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
108
+ "[#{timestamp}] #{severity}: #{stripped_msg}\n"
26
109
  end
27
110
  end
28
111
 
29
- class ColorFormatter < Logger::Formatter
30
- def call(_severity, _time, _progname, msg)
31
- "#{msg}\n"
112
+ # Colored log formatter for terminal output
113
+ #
114
+ # This formatter adds appropriate colors to different log levels
115
+ # to improve readability in terminal environments. Colors are:
116
+ # DEBUG (light blue), INFO (green), WARN (yellow), ERROR (red), FATAL (bold red)
117
+ #
118
+ # @deprecated This class is deprecated and will be removed in version 0.2.0.
119
+ # Use Makit::Logging::Logger with Makit::Logging::Sinks::Console instead.
120
+ class ColorFormatter < ::Logger::Formatter
121
+ # Format a log message with colors
122
+ #
123
+ # @param severity [String] log level (DEBUG, INFO, WARN, ERROR, FATAL)
124
+ # @param time [Time] timestamp of the log message
125
+ # @param _progname [String] program name (unused)
126
+ # @param msg [String] the log message content
127
+ # @return [String] formatted colored log entry
128
+ def call(severity, time, _progname, msg)
129
+ warn "Makit::Logging::ColorFormatter is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger with Makit::Logging::Sinks::Console instead."
130
+ timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
131
+ colored_severity = colorize_severity(severity)
132
+ "[#{timestamp}] #{colored_severity}: #{msg}\n"
133
+ end
134
+
135
+ private
136
+
137
+ def colorize_severity(severity)
138
+ case severity
139
+ when "DEBUG"
140
+ severity.light_blue
141
+ when "INFO"
142
+ severity.green
143
+ when "WARN"
144
+ severity.yellow
145
+ when "ERROR"
146
+ severity.red
147
+ when "FATAL"
148
+ severity.red.bold
149
+ else
150
+ severity
151
+ end
152
+ end
153
+ end
154
+
155
+ # Structured JSON log formatter
156
+ #
157
+ # This formatter outputs log messages as JSON objects with structured
158
+ # fields including timestamp, level, message, and program name.
159
+ # Useful for log aggregation systems and machine parsing.
160
+ #
161
+ # @deprecated This class is deprecated and will be removed in version 0.2.0.
162
+ # Use Makit::Logging::Logger with Makit::Logging::Sinks::FileSink (formatter: :json) instead.
163
+ class StructuredFormatter < ::Logger::Formatter
164
+ # Format a log message as JSON
165
+ #
166
+ # @param severity [String] log level (DEBUG, INFO, WARN, ERROR, FATAL)
167
+ # @param time [Time] timestamp of the log message
168
+ # @param progname [String] program name
169
+ # @param msg [String] the log message content
170
+ # @return [String] JSON formatted log entry with newline
171
+ def call(severity, time, progname, msg)
172
+ warn "Makit::Logging::StructuredFormatter is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger with Makit::Logging::Sinks::FileSink (formatter: :json) instead."
173
+ timestamp = time.strftime("%Y-%m-%d %H:%M:%S.%L")
174
+ {
175
+ timestamp: timestamp,
176
+ level: severity,
177
+ message: msg,
178
+ progname: progname,
179
+ }.to_json + "\n"
32
180
  end
33
181
  end
34
182
 
35
- # This class provide methods for working with Directories/
183
+ # Multi-target logger that writes to multiple destinations
36
184
  #
37
- # Example:
185
+ # This logger allows writing log messages to multiple targets simultaneously,
186
+ # such as both stdout and a file, or multiple files with different formats.
38
187
  #
39
- # Makit::Directory.find_directory_with_pattern("/home/user", "*.rb")
188
+ # @deprecated This class is deprecated and will be removed in version 0.2.0.
189
+ # Use Makit::Logging::Logger with multiple middleware instead.
40
190
  #
191
+ # @example Create a logger that writes to both console and file
192
+ # stdout_logger = Logger.new($stdout)
193
+ # file_logger = Logger.new("app.log")
194
+ # multi_logger = MultiLogger.new(stdout_logger, file_logger)
195
+ # multi_logger.info("This goes to both destinations")
41
196
  class MultiLogger
197
+ # Initialize a new MultiLogger with multiple logging targets
198
+ #
199
+ # @param targets [Array<Logger>] One or more logger instances to write to
42
200
  def initialize(*targets)
201
+ warn "Makit::Logging::MultiLogger is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger with middleware instead."
43
202
  @targets = targets
44
203
  end
45
204
 
205
+ # Add a message to all logger targets
206
+ #
207
+ # @param severity [Integer] The severity level (::Logger::DEBUG, ::Logger::INFO, etc.)
208
+ # @param message [String, nil] The message to log (or nil if using block)
209
+ # @param progname [String, nil] The program name to include in the log
210
+ # @param block [Proc, nil] Optional block that returns the message to log
211
+ # @return [nil]
46
212
  def add(severity, message = nil, progname = nil, &block)
47
213
  @targets.each do |logger|
48
214
  logger.add(severity, message, progname, &block)
@@ -50,6 +216,10 @@ module Makit
50
216
  end
51
217
  end
52
218
 
219
+ # Append a message directly to all logger targets
220
+ #
221
+ # @param message [String] The message to append to all loggers
222
+ # @return [nil]
53
223
  def <<(message)
54
224
  @targets.each do |logger|
55
225
  logger << message
@@ -57,50 +227,295 @@ module Makit
57
227
  end
58
228
  end
59
229
 
230
+ # Close all logger targets
231
+ #
232
+ # @return [nil]
60
233
  def close
61
234
  @targets.each(&:close)
62
235
  end
63
236
 
64
- def method_missing(method, *args, &block)
65
- @targets.each { |logger| logger.send(method, *args, &block) }
237
+ # Forward any unknown methods to all logger targets
238
+ #
239
+ # This allows calling standard Logger methods like info, debug, error, etc.
240
+ # directly on the MultiLogger instance.
241
+ #
242
+ # @param method [Symbol] The method name to forward
243
+ # @param args [Array] Arguments to pass to the method
244
+ # @return [nil]
245
+ def method_missing(method, ...)
246
+ @targets.each { |logger| logger.send(method, ...) }
66
247
  end
67
248
 
249
+ # Check if all logger targets respond to a given method
250
+ #
251
+ # @param method [Symbol] The method name to check
252
+ # @param include_private [Boolean] Whether to include private methods
253
+ # @return [Boolean] True if all logger targets respond to the method
68
254
  def respond_to_missing?(method, include_private = false)
69
255
  @targets.all? { |logger| logger.respond_to?(method, include_private) }
70
256
  end
71
257
 
72
- def self.create_logger
73
- stdout_logger = Logger.new($stdout) # ColoredLogger.new(STDOUT)
74
- stdout_logger.level = Logger::DEBUG
75
- # Assign the custom formatter to the file_logger
258
+ # Create a configured logger based on options
259
+ #
260
+ # This factory method creates a logger configured with appropriate formatters
261
+ # and targets based on the provided options. By default, it creates a logger
262
+ # that writes to both stdout (with colors) and a log file (plain text).
263
+ #
264
+ # @deprecated This method is deprecated and will be removed in version 0.2.0.
265
+ # Use Makit::Logging::Logger.new with middleware instead.
266
+ #
267
+ # @param options [Hash] Logger configuration options
268
+ # @option options [Symbol] :level (:info) The log level (:debug, :info, :warn, :error, :fatal)
269
+ # @option options [Boolean] :file_logging (true) Whether to log to a file
270
+ # @option options [String] :log_file (nil) Custom log file path, defaults to rake task-based path
271
+ # @option options [Boolean] :structured_logging (false) Whether to use JSON structured logging for file output
272
+ # @return [Logger, MultiLogger] A configured logger instance
273
+ def self.create_logger(options = {})
274
+ warn "Makit::Logging::MultiLogger.create_logger is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger.new with middleware instead."
275
+ log_level = options[:level] || DEFAULT_LOG_LEVEL
276
+ log_level = LOG_LEVELS[log_level] || LOG_LEVELS[DEFAULT_LOG_LEVEL]
277
+
278
+ stdout_logger = ::Logger.new($stdout)
279
+ stdout_logger.level = log_level
76
280
  stdout_logger.formatter = ColorFormatter.new
77
281
 
78
282
  # if clean or clobber commands are used, then log ONLY to stdout
79
- if ARGV.include?("clean") || ARGV.include?("clobber")
80
- return stdout_logger
283
+ return stdout_logger if ARGV.include?("clean") || ARGV.include?("clobber")
284
+
285
+ return stdout_logger if Makit::Environment.project_root_directory.nil?
286
+
287
+ # Create file logger if logging to file is enabled
288
+ if options[:file_logging] != false
289
+ log_filename = create_log_filename(options)
290
+ file_logger = create_file_logger(log_filename, log_level, options)
291
+ return MultiLogger.new(file_logger, stdout_logger)
81
292
  end
82
- if Makit::Environment.project_root_directory.nil?
83
- logger = stdout_logger
293
+
294
+ stdout_logger
295
+ end
296
+
297
+ # Create a file logger with appropriate formatter
298
+ #
299
+ # Creates a logger that writes to a file with the specified formatter
300
+ # and log level. Ensures the directory for the log file exists.
301
+ #
302
+ # @param log_filename [String] Path where log file should be created
303
+ # @param log_level [Integer] Log level to set (from Logger constants)
304
+ # @param options [Hash] Configuration options
305
+ # @option options [Boolean] :structured_logging (false) Whether to use JSON formatted logs
306
+ # @return [Logger] Configured file logger
307
+ def self.create_file_logger(log_filename, log_level, options)
308
+ FileUtils.mkdir_p(File.dirname(log_filename))
309
+
310
+ file_logger = ::Logger.new(log_filename)
311
+ file_logger.level = log_level
312
+
313
+ # Use structured logging for file output if requested
314
+ file_logger.formatter = if options[:structured_logging]
315
+ StructuredFormatter.new
316
+ else
317
+ PlainFormatter.new
318
+ end
319
+
320
+ file_logger
321
+ end
322
+
323
+ # Determine the appropriate log filename
324
+ #
325
+ # Generates a log filename based on options and the current rake task.
326
+ # If a custom log file is specified in options, that is used. Otherwise,
327
+ # a log file is created in the artifacts directory with a name based on
328
+ # the current rake task.
329
+ #
330
+ # @param options [Hash] Configuration options
331
+ # @option options [String] :log_file (nil) Custom log file path
332
+ # @return [String] The path to use for the log file
333
+ def self.create_log_filename(options)
334
+ if options[:log_file]
335
+ options[:log_file]
336
+ elsif ARGV.empty?
337
+ "#{Makit::Environment.project_root_directory}/artifacts/rake.log"
84
338
  else
85
- #log_filename = if ARGV.empty?
86
- # "#{Makit::Environment.project_root_directory}/artifacts/rake.log"
87
- # else
88
- # "#{Makit::Environment.project_root_directory}/artifacts/rake_#{ARGV.join("_").gsub(":",
89
- # "_")}.log"
90
- # end
91
- # FileUtils.remove_file(log_file) if File.exist?(log_file)
92
- #FileUtils.mkdir_p(File.dirname(log_filename)) unless Dir.exist?(File.dirname(log_filename))
93
- #File.open(log_filename, "w")
94
- #file_logger = Logger.new(log_filename)
95
- #file_logger.level = Logger::DEBUG
96
- # Assign the custom formatter to the file_logger
97
- #file_logger.formatter = PlainFormatter.new
98
- #logger = MultiLogger.new(file_logger, stdout_logger)
99
- logger = stdout_logger
339
+ task_name = ARGV.join("_").gsub(":", "_")
340
+ "#{Makit::Environment.project_root_directory}/artifacts/rake_#{task_name}.log"
100
341
  end
101
-
102
- logger
103
342
  end
104
343
  end
344
+
345
+ # ===== DEPRECATED LEGACY LOGGING =====
346
+ #
347
+ # The following classes and methods are deprecated and will be removed in version 0.2.0:
348
+ # - PlainFormatter
349
+ # - ColorFormatter
350
+ # - StructuredFormatter
351
+ # - MultiLogger
352
+ # - MultiLogger.create_logger
353
+ #
354
+ # MIGRATION GUIDE:
355
+ #
356
+ # OLD (deprecated):
357
+ # logger = Makit::Logging::MultiLogger.create_logger
358
+ # logger.info("message")
359
+ #
360
+ # NEW (recommended):
361
+ # Makit::Logging.info("message") # Uses default logger
362
+ # # OR
363
+ # logger = Makit::Logging::Logger.new(sinks: [...])
364
+ # logger.info("message")
365
+ #
366
+ # For custom formatting, use sinks:
367
+ # logger = Makit::Logging::Logger.new(
368
+ # sinks: [
369
+ # Makit::Logging::Sinks::Console.new,
370
+ # Makit::Logging::Sinks::FileSink.new(log_file: "app.log")
371
+ # ]
372
+ # )
373
+
374
+ # ===== NEW LOGGING ARCHITECTURE =====
375
+
376
+ # Default logger with unified file sink
377
+ # This replaces the previous multi-sink approach with a single, configurable sink
378
+ DEFAULT_LOGGER = Logger.new(
379
+ level: current_log_level,
380
+ sinks: [
381
+ Sinks::UnifiedFileSink.new(
382
+ configurations: [
383
+ # Console output with colors and symbols
384
+ {
385
+ file: $stdout,
386
+ format: :console,
387
+ show_timestamp: false,
388
+ show_level: false,
389
+ },
390
+ # Main log file in JSON format
391
+ {
392
+ file: "artifacts/makit.log",
393
+ format: :json,
394
+ append: true,
395
+ include_metadata: true,
396
+ },
397
+ # Debug log file in text format
398
+ {
399
+ file: "artifacts/debug.log",
400
+ format: :text,
401
+ append: true,
402
+ min_level: :debug,
403
+ include_context: true,
404
+ },
405
+ ],
406
+ ),
407
+ ],
408
+ )
409
+
410
+ # Convenience methods that delegate to the default logger
411
+ # These provide a simple API for common logging operations
412
+
413
+ # Log an info message
414
+ #
415
+ # @param message [String] the log message
416
+ # @param context [Hash] additional context information
417
+ # @return [void]
418
+ def self.info(message, context = {})
419
+ DEFAULT_LOGGER.info(message, context)
420
+ end
421
+
422
+ # Log a success message
423
+ #
424
+ # @param message [String] the log message
425
+ # @param context [Hash] additional context information
426
+ # @return [void]
427
+ def self.success(message, context = {})
428
+ DEFAULT_LOGGER.success(message, context)
429
+ end
430
+
431
+ # Log an error message
432
+ #
433
+ # @param message [String] the log message
434
+ # @param context [Hash] additional context information
435
+ # @return [void]
436
+ def self.error(message, context = {})
437
+ DEFAULT_LOGGER.error(message, context)
438
+ end
439
+
440
+ # Log a warning message
441
+ #
442
+ # @param message [String] the log message
443
+ # @param context [Hash] additional context information
444
+ # @return [void]
445
+ def self.warn(message, context = {})
446
+ DEFAULT_LOGGER.warn(message, context)
447
+ end
448
+
449
+ # Log a debug message
450
+ #
451
+ # @param message [String] the log message
452
+ # @param context [Hash] additional context information
453
+ # @return [void]
454
+ def self.debug(message, context = {})
455
+ DEFAULT_LOGGER.debug(message, context)
456
+ end
457
+
458
+ # Log a fatal message
459
+ #
460
+ # @param message [String] the log message
461
+ # @param context [Hash] additional context information
462
+ # @return [void]
463
+ def self.fatal(message, context = {})
464
+ DEFAULT_LOGGER.fatal(message, context)
465
+ end
466
+
467
+ # Create a logger with environment-specific configuration
468
+ #
469
+ # @param environment [Symbol] environment name (:development, :production, :test, :ci)
470
+ # @return [Logger] configured logger instance
471
+ def self.create_logger(environment: :default)
472
+ config = case environment
473
+ when :development
474
+ Configuration.development_config
475
+ when :production
476
+ Configuration.production_config
477
+ when :test
478
+ Configuration.test_config
479
+ when :ci
480
+ Configuration.ci_config
481
+ else
482
+ Configuration.default_config
483
+ end
484
+
485
+ Logger.new(
486
+ sinks: [
487
+ Sinks::UnifiedFileSink.new(configurations: config.configurations),
488
+ ],
489
+ )
490
+ end
491
+
492
+ # Create a logger from configuration file
493
+ #
494
+ # @param config_file [String] path to configuration file (YAML or JSON)
495
+ # @return [Logger] configured logger instance
496
+ def self.create_logger_from_file(config_file)
497
+ config = if config_file.end_with?(".yaml") || config_file.end_with?(".yml")
498
+ Configuration.from_yaml(config_file)
499
+ elsif config_file.end_with?(".json")
500
+ Configuration.from_json(config_file)
501
+ else
502
+ raise ArgumentError, "Configuration file must be YAML (.yaml/.yml) or JSON (.json)"
503
+ end
504
+
505
+ config.validate!
506
+
507
+ Logger.new(
508
+ sinks: [
509
+ Sinks::UnifiedFileSink.new(configurations: config.configurations),
510
+ ],
511
+ )
512
+ end
513
+
514
+ # Get the default logger instance
515
+ #
516
+ # @return [Logger] the default logger
517
+ def self.default_logger
518
+ DEFAULT_LOGGER
519
+ end
105
520
  end
106
521
  end
@@ -16,20 +16,20 @@ module Makit
16
16
 
17
17
  def self.get_command_markdown(command)
18
18
  md = "<details>\n"
19
- md += "<summary>#{Makit::Humanize::get_command_summary(command)}</summary>\n\n"
19
+ md += "<summary>#{Makit::Humanize.get_command_summary(command)}</summary>\n\n"
20
20
 
21
- if command.output.length > 0
22
- md += "<table><tr><th>output</th></tr><tr><td>\n\n" #<pre>\n"
21
+ if command.output.length.positive?
22
+ md += "<table><tr><th>output</th></tr><tr><td>\n\n" # <pre>\n"
23
23
  md += "```shell\n"
24
24
  md += "#{command.output}\n"
25
25
  md += "```\n\n"
26
26
  md += "</td></tr></table>\n\n"
27
- #md += "output:\n"
28
- #md += "```shell\n"
29
- #md += "#{command.output}\n"
30
- #md += "```\n\n"
27
+ # md += "output:\n"
28
+ # md += "```shell\n"
29
+ # md += "#{command.output}\n"
30
+ # md += "```\n\n"
31
31
  end
32
- if command.error.length > 0
32
+ if command.error.length.positive?
33
33
  md += "error:\n"
34
34
  md += "```shell\n"
35
35
  md += "#{command.error}\n"
@@ -37,17 +37,17 @@ module Makit
37
37
  end
38
38
  md += "| exit code | started at | duration | user | device | os | directory |\n"
39
39
  md += "| --- | --- | --- | --- | --- | --- | --- |\n"
40
- md += "| #{command.exit_code} | #{Makit::Humanize::get_protobuf_timestamp(command.started_at)} | #{Makit::Humanize::get_protobuf_duration(command.duration)} | #{command.user} | #{command.device} | #{command.os} | #{command.directory} |\n"
40
+ md += "| #{command.exit_code} | #{Makit::Humanize.get_protobuf_timestamp(command.started_at)} | #{Makit::Humanize.get_protobuf_duration(command.duration)} | #{command.user} | #{command.device} | #{command.os} | #{command.directory} |\n"
41
41
 
42
- #md += "| Name | Value |\n"
43
- #md += "| --- | --- |\n"
44
- #md += "| exit code | #{command.exit_code} |\n"
45
- #md += "| started at | #{Makit::Humanize::get_protobuf_timestamp(command.started_at)} |\n"
46
- #md += "| duration | #{Makit::Humanize::get_protobuf_duration(command.duration)} |\n"
47
- #md += "| user | #{command.user} |\n"
48
- #md += "| device | #{command.device} |\n"
49
- #md += "| os | #{command.os} |\n"
50
- #md += "| directory | #{command.directory} |\n"
42
+ # md += "| Name | Value |\n"
43
+ # md += "| --- | --- |\n"
44
+ # md += "| exit code | #{command.exit_code} |\n"
45
+ # md += "| started at | #{Makit::Humanize::get_protobuf_timestamp(command.started_at)} |\n"
46
+ # md += "| duration | #{Makit::Humanize::get_protobuf_duration(command.duration)} |\n"
47
+ # md += "| user | #{command.user} |\n"
48
+ # md += "| device | #{command.device} |\n"
49
+ # md += "| os | #{command.os} |\n"
50
+ # md += "| directory | #{command.directory} |\n"
51
51
  md += "</details>\n"
52
52
  md
53
53
  end
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "json"
3
4
  require "yaml"
4
5
 
5
6
  # monkey patch String class with a run method
6
7
 
7
8
  class BasicObject
8
- def to_json
9
- self.to_json
9
+ def to_json(*_args)
10
+ to_json
10
11
  end
11
12
 
12
13
  def to_pretty_json
13
- json = self.to_json
14
+ json = to_json
14
15
  ::JSON.pretty_generate(::JSON.parse(json))
15
16
  end
16
- end # class BasicObject
17
+ end
@@ -4,10 +4,10 @@ module Makit
4
4
  module V1
5
5
  class Command
6
6
  def to_markdown
7
- md = "## " + self.name + " " + self.arguments.join(" ") + "\n\n"
8
- md += "```\n" + self.output + "\n```\n"
7
+ md = "## #{name} #{arguments.join(" ")}\n\n"
8
+ md += "```\n#{output}\n```\n"
9
9
  md
10
10
  end
11
- end # class Command
12
- end # module V1
13
- end # module Makit
11
+ end
12
+ end
13
+ end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "digest"
3
4
 
4
5
  module Makit
5
6
  module V1
6
- #class CommandRequest
7
+ # class CommandRequest
7
8
  # def to_hash
8
9
  # int_hash = Digest::SHA256.hexdigest("{self.name}.#{self.arguments.join(" ")}")
9
10
  # int_hash
@@ -13,4 +14,4 @@ module Makit
13
14
  # end
14
15
  # end
15
16
  end
16
- end # module Makit
17
+ end