makit 0.0.98 → 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.
- checksums.yaml +4 -4
- data/README.md +41 -0
- data/exe/makit +5 -0
- data/lib/makit/apache.rb +7 -11
- data/lib/makit/cli/build_commands.rb +500 -0
- data/lib/makit/cli/generators/base_generator.rb +74 -0
- data/lib/makit/cli/generators/dotnet_generator.rb +50 -0
- data/lib/makit/cli/generators/generator_factory.rb +49 -0
- data/lib/makit/cli/generators/node_generator.rb +50 -0
- data/lib/makit/cli/generators/ruby_generator.rb +77 -0
- data/lib/makit/cli/generators/rust_generator.rb +50 -0
- data/lib/makit/cli/generators/templates/dotnet_templates.rb +167 -0
- data/lib/makit/cli/generators/templates/node_templates.rb +161 -0
- data/lib/makit/cli/generators/templates/ruby/gemfile.rb +26 -0
- data/lib/makit/cli/generators/templates/ruby/gemspec.rb +40 -0
- data/lib/makit/cli/generators/templates/ruby/main_lib.rb +33 -0
- data/lib/makit/cli/generators/templates/ruby/rakefile.rb +35 -0
- data/lib/makit/cli/generators/templates/ruby/readme.rb +63 -0
- data/lib/makit/cli/generators/templates/ruby/test.rb +39 -0
- data/lib/makit/cli/generators/templates/ruby/test_helper.rb +29 -0
- data/lib/makit/cli/generators/templates/ruby/version.rb +29 -0
- data/lib/makit/cli/generators/templates/rust_templates.rb +128 -0
- data/lib/makit/cli/main.rb +48 -19
- data/lib/makit/cli/project_commands.rb +868 -0
- data/lib/makit/cli/repository_commands.rb +661 -0
- data/lib/makit/cli/utility_commands.rb +521 -0
- data/lib/makit/command_runner.rb +187 -128
- data/lib/makit/commands/compatibility.rb +365 -0
- data/lib/makit/commands/factory.rb +359 -0
- data/lib/makit/commands/middleware/base.rb +73 -0
- data/lib/makit/commands/middleware/cache.rb +248 -0
- data/lib/makit/commands/middleware/command_logger.rb +323 -0
- data/lib/makit/commands/middleware/unified_logger.rb +243 -0
- data/lib/makit/commands/middleware/validator.rb +269 -0
- data/lib/makit/commands/request.rb +254 -0
- data/lib/makit/commands/result.rb +323 -0
- data/lib/makit/commands/runner.rb +317 -0
- data/lib/makit/commands/strategies/base.rb +160 -0
- data/lib/makit/commands/strategies/synchronous.rb +134 -0
- data/lib/makit/commands.rb +24 -3
- data/lib/makit/configuration/gitlab_helper.rb +60 -0
- data/lib/makit/configuration/project.rb +127 -0
- data/lib/makit/configuration/rakefile_helper.rb +43 -0
- data/lib/makit/configuration/step.rb +34 -0
- data/lib/makit/configuration.rb +14 -0
- data/lib/makit/content/default_gitignore.rb +4 -2
- data/lib/makit/content/default_rakefile.rb +4 -2
- data/lib/makit/content/gem_rakefile.rb +4 -2
- data/lib/makit/context.rb +1 -0
- data/lib/makit/data.rb +9 -10
- data/lib/makit/directories.rb +48 -52
- data/lib/makit/directory.rb +38 -52
- data/lib/makit/docs/files.rb +5 -10
- data/lib/makit/docs/rake.rb +16 -20
- data/lib/makit/dotnet/cli.rb +65 -0
- data/lib/makit/dotnet/project.rb +153 -0
- data/lib/makit/dotnet/solution.rb +38 -0
- data/lib/makit/dotnet/solution_classlib.rb +239 -0
- data/lib/makit/dotnet/solution_console.rb +264 -0
- data/lib/makit/dotnet/solution_maui.rb +354 -0
- data/lib/makit/dotnet/solution_wasm.rb +275 -0
- data/lib/makit/dotnet/solution_wpf.rb +304 -0
- data/lib/makit/dotnet.rb +54 -171
- data/lib/makit/email.rb +46 -17
- data/lib/makit/environment.rb +22 -19
- data/lib/makit/examples/runner.rb +370 -0
- data/lib/makit/exceptions.rb +45 -0
- data/lib/makit/fileinfo.rb +3 -5
- data/lib/makit/files.rb +12 -16
- data/lib/makit/gems.rb +40 -39
- data/lib/makit/git/cli.rb +54 -0
- data/lib/makit/git/repository.rb +90 -0
- data/lib/makit/git.rb +44 -91
- data/lib/makit/gitlab_runner.rb +0 -1
- data/lib/makit/humanize.rb +31 -23
- data/lib/makit/indexer.rb +15 -24
- data/lib/makit/logging/configuration.rb +305 -0
- data/lib/makit/logging/format_registry.rb +84 -0
- data/lib/makit/logging/formatters/base.rb +39 -0
- data/lib/makit/logging/formatters/console_formatter.rb +127 -0
- data/lib/makit/logging/formatters/json_formatter.rb +65 -0
- data/lib/makit/logging/formatters/plain_text_formatter.rb +71 -0
- data/lib/makit/logging/formatters/text_formatter.rb +64 -0
- data/lib/makit/logging/log_request.rb +115 -0
- data/lib/makit/logging/logger.rb +159 -0
- data/lib/makit/logging/sinks/base.rb +91 -0
- data/lib/makit/logging/sinks/console.rb +72 -0
- data/lib/makit/logging/sinks/file_sink.rb +92 -0
- data/lib/makit/logging/sinks/structured.rb +129 -0
- data/lib/makit/logging/sinks/unified_file_sink.rb +303 -0
- data/lib/makit/logging.rb +452 -37
- data/lib/makit/markdown.rb +18 -18
- data/lib/makit/mp/basic_object_mp.rb +5 -4
- data/lib/makit/mp/command_mp.rb +5 -5
- data/lib/makit/mp/command_request.mp.rb +3 -2
- data/lib/makit/mp/project_mp.rb +85 -96
- data/lib/makit/mp/string_mp.rb +245 -73
- data/lib/makit/nuget.rb +27 -25
- data/lib/makit/port.rb +25 -27
- data/lib/makit/process.rb +127 -29
- data/lib/makit/protoc.rb +27 -24
- data/lib/makit/rake/cli.rb +196 -0
- data/lib/makit/rake.rb +6 -6
- data/lib/makit/ruby/cli.rb +185 -0
- data/lib/makit/ruby.rb +25 -0
- data/lib/makit/secrets.rb +18 -18
- data/lib/makit/serializer.rb +29 -27
- data/lib/makit/services/builder.rb +186 -0
- data/lib/makit/services/error_handler.rb +226 -0
- data/lib/makit/services/repository_manager.rb +229 -0
- data/lib/makit/services/validator.rb +112 -0
- data/lib/makit/setup/classlib.rb +53 -0
- data/lib/makit/setup/gem.rb +250 -0
- data/lib/makit/setup/runner.rb +40 -0
- data/lib/makit/show.rb +16 -16
- data/lib/makit/storage.rb +32 -37
- data/lib/makit/symbols.rb +12 -0
- data/lib/makit/task_hooks.rb +125 -0
- data/lib/makit/task_info.rb +63 -21
- data/lib/makit/tasks/at_exit.rb +13 -0
- data/lib/makit/tasks/build.rb +18 -0
- data/lib/makit/tasks/clean.rb +11 -0
- data/lib/makit/tasks/hook_manager.rb +239 -0
- data/lib/makit/tasks/init.rb +47 -0
- data/lib/makit/tasks/integrate.rb +15 -0
- data/lib/makit/tasks/pull_incoming.rb +12 -0
- data/lib/makit/tasks/setup.rb +6 -0
- data/lib/makit/tasks/sync.rb +11 -0
- data/lib/makit/tasks/task_monkey_patch.rb +79 -0
- data/lib/makit/tasks.rb +5 -150
- data/lib/makit/test_cache.rb +239 -0
- data/lib/makit/v1/makit.v1_pb.rb +34 -35
- data/lib/makit/v1/makit.v1_services_pb.rb +2 -0
- data/lib/makit/version.rb +1 -60
- data/lib/makit/wix.rb +23 -23
- data/lib/makit/yaml.rb +18 -6
- data/lib/makit.rb +2 -261
- metadata +109 -145
- data/lib/makit/cli/clean.rb +0 -14
- data/lib/makit/cli/clone.rb +0 -59
- data/lib/makit/cli/init.rb +0 -38
- data/lib/makit/cli/make.rb +0 -54
- data/lib/makit/cli/new.rb +0 -37
- data/lib/makit/cli/nuget_cache.rb +0 -38
- data/lib/makit/cli/pull.rb +0 -31
- data/lib/makit/cli/setup.rb +0 -71
- data/lib/makit/cli/work.rb +0 -21
- data/lib/makit/content/default_gitignore.txt +0 -222
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Makit
|
6
|
+
module Logging
|
7
|
+
module Formatters
|
8
|
+
# Text formatter with timestamp and log level
|
9
|
+
#
|
10
|
+
# Formats log requests as human-readable text with timestamp, log level,
|
11
|
+
# and message. This is the most common format for traditional log files.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# formatter = TextFormatter.new
|
15
|
+
# formatted = formatter.format(log_request)
|
16
|
+
# # => '[2024-01-15 10:30:45] INFO User logged in'
|
17
|
+
class TextFormatter < Base
|
18
|
+
# @return [String] timestamp format string
|
19
|
+
attr_reader :timestamp_format
|
20
|
+
# @return [Boolean] whether to include context in output
|
21
|
+
attr_reader :include_context
|
22
|
+
|
23
|
+
# Initialize text formatter
|
24
|
+
#
|
25
|
+
# @param timestamp_format [String] strftime format for timestamps
|
26
|
+
# @param include_context [Boolean] whether to include context in output
|
27
|
+
def initialize(timestamp_format: "%Y-%m-%d %H:%M:%S", include_context: false)
|
28
|
+
@timestamp_format = timestamp_format
|
29
|
+
@include_context = include_context
|
30
|
+
end
|
31
|
+
|
32
|
+
# Format log request as text
|
33
|
+
#
|
34
|
+
# @param log_request [LogRequest] the log request to format
|
35
|
+
# @return [String] text formatted log entry
|
36
|
+
def format(log_request)
|
37
|
+
timestamp = log_request.timestamp.strftime(@timestamp_format)
|
38
|
+
level = log_request.level.to_s.upcase
|
39
|
+
message = log_request.message
|
40
|
+
|
41
|
+
formatted = "[#{timestamp}] #{level} #{message}"
|
42
|
+
|
43
|
+
# Add context if enabled and present
|
44
|
+
if @include_context && !log_request.context.empty?
|
45
|
+
context_str = log_request.context.map { |k, v| "#{k}=#{v}" }.join(" ")
|
46
|
+
formatted += " #{context_str}"
|
47
|
+
end
|
48
|
+
|
49
|
+
formatted
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get formatter configuration
|
53
|
+
#
|
54
|
+
# @return [Hash] formatter configuration
|
55
|
+
def config
|
56
|
+
super.merge(
|
57
|
+
timestamp_format: @timestamp_format,
|
58
|
+
include_context: @include_context,
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Makit
|
4
|
+
module Logging
|
5
|
+
# Represents a log request that flows through the logging middleware chain
|
6
|
+
#
|
7
|
+
# This class encapsulates all the information needed for a log entry,
|
8
|
+
# including the log level, message, context, and metadata. It provides
|
9
|
+
# a clean interface for middleware to process and modify log information.
|
10
|
+
#
|
11
|
+
# @example Basic usage
|
12
|
+
# request = LogRequest.new(:info, "Processing started")
|
13
|
+
# request.add_metadata(process_id: 12345)
|
14
|
+
# puts request.to_h
|
15
|
+
#
|
16
|
+
# @example With context
|
17
|
+
# request = LogRequest.new(:error, "Build failed", {
|
18
|
+
# repository: "user/repo",
|
19
|
+
# commit: "abc123"
|
20
|
+
# })
|
21
|
+
class LogRequest
|
22
|
+
# @return [Symbol] the log level (:debug, :info, :warn, :error, :fatal, :success)
|
23
|
+
attr_reader :level
|
24
|
+
|
25
|
+
# @return [String] the log message
|
26
|
+
attr_reader :message
|
27
|
+
|
28
|
+
# @return [Hash] additional context information
|
29
|
+
attr_reader :context
|
30
|
+
|
31
|
+
# @return [Hash] metadata about the log entry
|
32
|
+
attr_reader :metadata
|
33
|
+
|
34
|
+
# @return [Time] when the log request was created
|
35
|
+
attr_reader :timestamp
|
36
|
+
|
37
|
+
# Initialize a new log request
|
38
|
+
#
|
39
|
+
# @param level [Symbol] the log level
|
40
|
+
# @param message [String] the log message
|
41
|
+
# @param context [Hash] additional context information
|
42
|
+
def initialize(level, message, context = {})
|
43
|
+
@level = level
|
44
|
+
@message = message
|
45
|
+
@context = context.dup
|
46
|
+
@metadata = {}
|
47
|
+
@timestamp = Time.now
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add metadata to the log request
|
51
|
+
#
|
52
|
+
# @param data [Hash] metadata to add
|
53
|
+
# @return [void]
|
54
|
+
def add_metadata(data)
|
55
|
+
@metadata.merge!(data)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Convert the log request to a hash representation
|
59
|
+
#
|
60
|
+
# @return [Hash] hash representation of the log request
|
61
|
+
def to_h
|
62
|
+
{
|
63
|
+
level: @level,
|
64
|
+
message: @message,
|
65
|
+
context: @context,
|
66
|
+
metadata: @metadata,
|
67
|
+
timestamp: @timestamp.iso8601,
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
# Convert the log request to a JSON string
|
72
|
+
#
|
73
|
+
# @return [String] JSON representation of the log request
|
74
|
+
def to_json
|
75
|
+
require "json"
|
76
|
+
JSON.generate(to_h)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Get a formatted string representation
|
80
|
+
#
|
81
|
+
# @return [String] formatted string representation
|
82
|
+
def to_s
|
83
|
+
"[#{@timestamp.strftime("%Y-%m-%d %H:%M:%S")}] #{@level.to_s.upcase}: #{@message}"
|
84
|
+
end
|
85
|
+
|
86
|
+
# Check if this is an error level log
|
87
|
+
#
|
88
|
+
# @return [Boolean] true if error level
|
89
|
+
def error?
|
90
|
+
@level == :error || @level == :fatal
|
91
|
+
end
|
92
|
+
|
93
|
+
# Check if this is a success level log
|
94
|
+
#
|
95
|
+
# @return [Boolean] true if success level
|
96
|
+
def success?
|
97
|
+
@level == :success
|
98
|
+
end
|
99
|
+
|
100
|
+
# Check if this is an info level log
|
101
|
+
#
|
102
|
+
# @return [Boolean] true if info level
|
103
|
+
def info?
|
104
|
+
@level == :info
|
105
|
+
end
|
106
|
+
|
107
|
+
# Check if this is a warning level log
|
108
|
+
#
|
109
|
+
# @return [Boolean] true if warn level
|
110
|
+
def warn?
|
111
|
+
@level == :warn
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,159 @@
|
|
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
|
+
log(:info, message, context)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Get logger configuration
|
123
|
+
#
|
124
|
+
# @return [Hash] logger configuration
|
125
|
+
def config
|
126
|
+
{
|
127
|
+
level: @level,
|
128
|
+
sinks_count: @sinks.length,
|
129
|
+
sinks: @sinks.map(&:config),
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
# Check if a log level should be processed
|
136
|
+
#
|
137
|
+
# @param level [Symbol] the log level to check
|
138
|
+
# @return [Boolean] true if the level should be logged
|
139
|
+
def should_log?(level)
|
140
|
+
levels = [:debug, :info, :warn, :error, :fatal, :success]
|
141
|
+
levels.index(level) >= levels.index(@level)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Execute the sink chain for a log request
|
145
|
+
#
|
146
|
+
# @param log_request [LogRequest] the log request to process
|
147
|
+
# @return [void]
|
148
|
+
def execute_sinks(log_request)
|
149
|
+
# Filter applicable sinks
|
150
|
+
applicable_sinks = @sinks.select { |s| s.applicable?(log_request) }
|
151
|
+
|
152
|
+
# Execute sink chain
|
153
|
+
applicable_sinks.reduce(log_request) do |request, sink|
|
154
|
+
sink.call(request)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
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
|