makit 0.0.99 → 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.
Files changed (152) 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 +28 -32
  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 +62 -33
  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/commands/factory.rb +359 -0
  28. data/lib/makit/commands/middleware/base.rb +73 -0
  29. data/lib/makit/commands/middleware/cache.rb +248 -0
  30. data/lib/makit/commands/middleware/command_logger.rb +320 -0
  31. data/lib/makit/commands/middleware/unified_logger.rb +243 -0
  32. data/lib/makit/commands/middleware/validator.rb +269 -0
  33. data/lib/makit/commands/request.rb +254 -0
  34. data/lib/makit/commands/result.rb +323 -0
  35. data/lib/makit/commands/runner.rb +337 -0
  36. data/lib/makit/commands/strategies/base.rb +160 -0
  37. data/lib/makit/commands/strategies/synchronous.rb +134 -0
  38. data/lib/makit/commands.rb +51 -21
  39. data/lib/makit/configuration/gitlab_helper.rb +60 -0
  40. data/lib/makit/configuration/project.rb +127 -0
  41. data/lib/makit/configuration/rakefile_helper.rb +43 -0
  42. data/lib/makit/configuration/step.rb +34 -0
  43. data/lib/makit/configuration.rb +14 -0
  44. data/lib/makit/content/default_gitignore.rb +7 -5
  45. data/lib/makit/content/default_rakefile.rb +13 -11
  46. data/lib/makit/content/gem_rakefile.rb +16 -14
  47. data/lib/makit/context.rb +1 -0
  48. data/lib/makit/data.rb +49 -50
  49. data/lib/makit/directories.rb +141 -145
  50. data/lib/makit/directory.rb +262 -276
  51. data/lib/makit/docs/files.rb +89 -94
  52. data/lib/makit/docs/rake.rb +102 -106
  53. data/lib/makit/dotnet/cli.rb +65 -0
  54. data/lib/makit/dotnet/project.rb +153 -0
  55. data/lib/makit/dotnet/solution.rb +38 -0
  56. data/lib/makit/dotnet/solution_classlib.rb +239 -0
  57. data/lib/makit/dotnet/solution_console.rb +264 -0
  58. data/lib/makit/dotnet/solution_maui.rb +354 -0
  59. data/lib/makit/dotnet/solution_wasm.rb +275 -0
  60. data/lib/makit/dotnet/solution_wpf.rb +304 -0
  61. data/lib/makit/dotnet.rb +102 -219
  62. data/lib/makit/email.rb +90 -61
  63. data/lib/makit/environment.rb +142 -139
  64. data/lib/makit/examples/runner.rb +370 -0
  65. data/lib/makit/exceptions.rb +45 -0
  66. data/lib/makit/fileinfo.rb +24 -26
  67. data/lib/makit/files.rb +43 -47
  68. data/lib/makit/gems.rb +29 -28
  69. data/lib/makit/git/cli.rb +54 -0
  70. data/lib/makit/git/repository.rb +90 -0
  71. data/lib/makit/git.rb +98 -145
  72. data/lib/makit/gitlab_runner.rb +59 -60
  73. data/lib/makit/humanize.rb +137 -129
  74. data/lib/makit/indexer.rb +47 -56
  75. data/lib/makit/logging/configuration.rb +305 -0
  76. data/lib/makit/logging/format_registry.rb +84 -0
  77. data/lib/makit/logging/formatters/base.rb +39 -0
  78. data/lib/makit/logging/formatters/console_formatter.rb +140 -0
  79. data/lib/makit/logging/formatters/json_formatter.rb +65 -0
  80. data/lib/makit/logging/formatters/plain_text_formatter.rb +71 -0
  81. data/lib/makit/logging/formatters/text_formatter.rb +64 -0
  82. data/lib/makit/logging/log_request.rb +115 -0
  83. data/lib/makit/logging/logger.rb +163 -0
  84. data/lib/makit/logging/sinks/base.rb +91 -0
  85. data/lib/makit/logging/sinks/console.rb +72 -0
  86. data/lib/makit/logging/sinks/file_sink.rb +92 -0
  87. data/lib/makit/logging/sinks/structured.rb +129 -0
  88. data/lib/makit/logging/sinks/unified_file_sink.rb +303 -0
  89. data/lib/makit/logging.rb +530 -106
  90. data/lib/makit/markdown.rb +75 -75
  91. data/lib/makit/mp/basic_object_mp.rb +17 -16
  92. data/lib/makit/mp/command_mp.rb +13 -13
  93. data/lib/makit/mp/command_request.mp.rb +17 -16
  94. data/lib/makit/mp/project_mp.rb +199 -210
  95. data/lib/makit/mp/string_mp.rb +193 -176
  96. data/lib/makit/nuget.rb +74 -72
  97. data/lib/makit/port.rb +32 -34
  98. data/lib/makit/process.rb +163 -65
  99. data/lib/makit/protoc.rb +107 -104
  100. data/lib/makit/rake/cli.rb +196 -0
  101. data/lib/makit/rake.rb +25 -25
  102. data/lib/makit/ruby/cli.rb +185 -0
  103. data/lib/makit/ruby.rb +25 -0
  104. data/lib/makit/secrets.rb +51 -51
  105. data/lib/makit/serializer.rb +130 -115
  106. data/lib/makit/services/builder.rb +186 -0
  107. data/lib/makit/services/error_handler.rb +226 -0
  108. data/lib/makit/services/repository_manager.rb +229 -0
  109. data/lib/makit/services/validator.rb +112 -0
  110. data/lib/makit/setup/classlib.rb +53 -0
  111. data/lib/makit/setup/gem.rb +263 -0
  112. data/lib/makit/setup/runner.rb +45 -0
  113. data/lib/makit/setup.rb +5 -0
  114. data/lib/makit/show.rb +110 -110
  115. data/lib/makit/storage.rb +126 -131
  116. data/lib/makit/symbols.rb +170 -149
  117. data/lib/makit/task_info.rb +128 -86
  118. data/lib/makit/tasks/at_exit.rb +13 -0
  119. data/lib/makit/tasks/build.rb +19 -0
  120. data/lib/makit/tasks/clean.rb +11 -0
  121. data/lib/makit/tasks/hook_manager.rb +393 -0
  122. data/lib/makit/tasks/init.rb +47 -0
  123. data/lib/makit/tasks/integrate.rb +17 -0
  124. data/lib/makit/tasks/pull_incoming.rb +11 -0
  125. data/lib/makit/tasks/setup.rb +6 -0
  126. data/lib/makit/tasks/sync.rb +12 -0
  127. data/lib/makit/tasks/tag.rb +15 -0
  128. data/lib/makit/tasks/task_monkey_patch.rb +79 -0
  129. data/lib/makit/tasks.rb +15 -150
  130. data/lib/makit/test_cache.rb +239 -0
  131. data/lib/makit/tree.rb +37 -37
  132. data/lib/makit/v1/makit.v1_pb.rb +3 -4
  133. data/lib/makit/v1/makit.v1_services_pb.rb +27 -25
  134. data/lib/makit/version.rb +5 -61
  135. data/lib/makit/version_util.rb +21 -0
  136. data/lib/makit/wix.rb +95 -95
  137. data/lib/makit/yaml.rb +29 -17
  138. data/lib/makit/zip.rb +17 -17
  139. data/lib/makit copy.rb +44 -0
  140. data/lib/makit.rb +40 -267
  141. metadata +117 -110
  142. data/lib/makit/cli/clean.rb +0 -14
  143. data/lib/makit/cli/clone.rb +0 -59
  144. data/lib/makit/cli/init.rb +0 -38
  145. data/lib/makit/cli/make.rb +0 -54
  146. data/lib/makit/cli/new.rb +0 -37
  147. data/lib/makit/cli/nuget_cache.rb +0 -38
  148. data/lib/makit/cli/pull.rb +0 -31
  149. data/lib/makit/cli/setup.rb +0 -71
  150. data/lib/makit/cli/work.rb +0 -21
  151. data/lib/makit/command_runner.rb +0 -404
  152. data/lib/makit/content/default_gitignore.txt +0 -222
@@ -0,0 +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
+ # 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
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Makit
4
+ module Logging
5
+ module Sinks
6
+ # Base class for all logging sinks
7
+ #
8
+ # Sinks provide a way to output log requests to various destinations like
9
+ # console, files, or external services. This follows the same pattern as
10
+ # the commands middleware but focuses on output rather than transformation.
11
+ #
12
+ # @example Creating a custom logging sink
13
+ # class CustomSink < Base
14
+ # def call(log_request, &block)
15
+ # # Output the log request
16
+ # output_log(log_request)
17
+ #
18
+ # # Continue to next sink
19
+ # block.call(log_request) if block_given?
20
+ # end
21
+ # end
22
+ class Base
23
+ # Execute sink logic
24
+ #
25
+ # This method must be implemented by subclasses to provide the actual
26
+ # sink functionality. The pattern is to output the log request to the
27
+ # destination, then call the block to continue the sink chain.
28
+ #
29
+ # @param log_request [LogRequest] the log request to process
30
+ # @yield [LogRequest] yields the processed log request to the next sink
31
+ # @yieldreturn [LogRequest] the processed log request
32
+ # @return [LogRequest] the final processed log request
33
+ # @raise [NotImplementedError] if not overridden by subclass
34
+ def call(log_request, &block)
35
+ raise NotImplementedError, "#{self.class.name} must implement #call"
36
+ end
37
+
38
+ # Check if this sink should be applied to the given log request
39
+ #
40
+ # Override this method to provide conditional sink application
41
+ # based on log request properties like level, message, or context.
42
+ #
43
+ # @param log_request [LogRequest] the log request
44
+ # @return [Boolean] true if sink should be applied
45
+ def applicable?(log_request)
46
+ true
47
+ end
48
+
49
+ # Get sink name for logging and debugging
50
+ #
51
+ # @return [String] sink name
52
+ def name
53
+ self.class.name.split("::").last
54
+ end
55
+
56
+ # Get sink configuration
57
+ #
58
+ # Override this method to provide sink-specific configuration.
59
+ #
60
+ # @return [Hash] sink configuration
61
+ def config
62
+ {}
63
+ end
64
+
65
+ private
66
+
67
+ # Pre-process the log request before outputting
68
+ #
69
+ # Override this method to modify the log request before it is output
70
+ # to the destination.
71
+ #
72
+ # @param log_request [LogRequest] the log request
73
+ # @return [LogRequest] the modified log request
74
+ def pre_process(log_request)
75
+ log_request
76
+ end
77
+
78
+ # Post-process the log request after outputting
79
+ #
80
+ # Override this method to perform any final processing after the
81
+ # log request has been output to the destination.
82
+ #
83
+ # @param log_request [LogRequest] the log request
84
+ # @return [LogRequest] the final log request
85
+ def post_process(log_request)
86
+ log_request
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module Makit
6
+ module Logging
7
+ module Sinks
8
+ # Structured sink for adding metadata to log requests
9
+ #
10
+ # This sink enriches log requests with structured metadata like
11
+ # process information, thread details, and other contextual data that
12
+ # can be useful for debugging and monitoring. It follows the same
13
+ # pattern as other sinks but focuses on data enrichment rather than output.
14
+ #
15
+ # @example Basic usage
16
+ # structured_sink = Structured.new
17
+ # logger = Logger.new(sinks: [structured_sink])
18
+ # logger.info("Processing started")
19
+ # # Adds metadata like process_id, thread_id, etc.
20
+ #
21
+ # @example With custom metadata
22
+ # structured_sink = Structured.new(
23
+ # custom_metadata: { environment: "production" }
24
+ # )
25
+ class Structured < Base
26
+ # Initialize structured sink
27
+ #
28
+ # @param include_process_info [Boolean] whether to include process information
29
+ # @param include_thread_info [Boolean] whether to include thread information
30
+ # @param include_timing [Boolean] whether to include timing information
31
+ # @param custom_metadata [Hash] custom metadata to add to all log requests
32
+ def initialize(include_process_info: true, include_thread_info: true, include_timing: true, custom_metadata: {})
33
+ @include_process_info = include_process_info
34
+ @include_thread_info = include_thread_info
35
+ @include_timing = include_timing
36
+ @custom_metadata = custom_metadata.dup
37
+ end
38
+
39
+ # Execute sink logic to add structured metadata
40
+ #
41
+ # @param log_request [LogRequest] the log request to process
42
+ # @yield [LogRequest] yields the processed log request to the next sink
43
+ # @yieldreturn [LogRequest] the processed log request
44
+ # @return [LogRequest] the final processed log request
45
+ def call(log_request, &block)
46
+ add_structured_metadata(log_request)
47
+ block&.call(log_request) if block_given?
48
+ log_request
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
+ include_process_info: @include_process_info,
58
+ include_thread_info: @include_thread_info,
59
+ include_timing: @include_timing,
60
+ custom_metadata: @custom_metadata,
61
+ }
62
+ end
63
+
64
+ private
65
+
66
+ # Add structured metadata to the log request
67
+ #
68
+ # @param log_request [LogRequest] the log request to enrich
69
+ def add_structured_metadata(log_request)
70
+ metadata = {}
71
+
72
+ # Add process information
73
+ if @include_process_info
74
+ metadata.merge!(get_process_metadata)
75
+ end
76
+
77
+ # Add thread information
78
+ if @include_thread_info
79
+ metadata.merge!(get_thread_metadata)
80
+ end
81
+
82
+ # Add timing information
83
+ if @include_timing
84
+ metadata.merge!(get_timing_metadata)
85
+ end
86
+
87
+ # Add custom metadata
88
+ metadata.merge!(@custom_metadata)
89
+
90
+ # Add to log request
91
+ log_request.add_metadata(metadata)
92
+ end
93
+
94
+ # Get process-related metadata
95
+ #
96
+ # @return [Hash] process metadata
97
+ def get_process_metadata
98
+ {
99
+ process_id: ::Process.pid,
100
+ process_title: $0,
101
+ ruby_version: RUBY_VERSION,
102
+ ruby_platform: RUBY_PLATFORM,
103
+ }
104
+ end
105
+
106
+ # Get thread-related metadata
107
+ #
108
+ # @return [Hash] thread metadata
109
+ def get_thread_metadata
110
+ {
111
+ thread_id: Thread.current.object_id,
112
+ thread_name: Thread.current.name || "main",
113
+ }
114
+ end
115
+
116
+ # Get timing-related metadata
117
+ #
118
+ # @return [Hash] timing metadata
119
+ def get_timing_metadata
120
+ {
121
+ timestamp: Time.now.iso8601,
122
+ unix_timestamp: Time.now.to_i,
123
+ timezone: Time.now.zone,
124
+ }
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end