Class: Cloudflare::AI::ContextualLogger
- Inherits:
-
Object
- Object
- Cloudflare::AI::ContextualLogger
show all
- Defined in:
- lib/cloudflare/ai/contextual_logger.rb
Constant Summary
collapse
- MESSAGE_COLOR_OPTIONS =
{
debug: {
color: :white
},
error: {
color: :red
},
fatal: {
color: :red,
background: :white,
mode: :bold
},
unknown: {
color: :white
},
info: {
color: :white
},
warn: {
color: :yellow,
mode: :bold
}
}
Instance Method Summary
collapse
Constructor Details
30
31
32
33
|
# File 'lib/cloudflare/ai/contextual_logger.rb', line 30
def initialize(logger)
@logger = logger
@levels = Logger::Severity.constants.map(&:downcase)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/cloudflare/ai/contextual_logger.rb', line 39
def method_missing(method, *args, **kwargs, &block)
return @logger.send(method, *args, **kwargs, &block) unless @levels.include?(method)
for_class = kwargs.delete(:for)
for_class_name = for_class&.name
log_line_parts = []
log_line_parts << "[cloudflare-ai]".colorize(color: :yellow)
log_line_parts << if for_class.respond_to?(:logger_options)
"[#{for_class_name}]".colorize(for_class.logger_options) + ":"
elsif for_class_name
"[#{for_class_name}]:"
end
log_line_parts << args.first.colorize(MESSAGE_COLOR_OPTIONS[method])
log_line = log_line_parts.compact.join(" ")
@logger.send(
method,
log_line
)
end
|
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
35
36
37
|
# File 'lib/cloudflare/ai/contextual_logger.rb', line 35
def respond_to_missing?(method, include_private = false)
@logger.respond_to?(method, include_private)
end
|