Class: Rack::AI::Utils::AdvancedLogger
- Inherits:
-
Object
- Object
- Rack::AI::Utils::AdvancedLogger
- Defined in:
- lib/rack/ai/utils/enhanced_logger.rb
Constant Summary collapse
- LOG_LEVELS =
{ debug: ::Logger::DEBUG, info: ::Logger::INFO, warn: ::Logger::WARN, error: ::Logger::ERROR, fatal: ::Logger::FATAL }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #debug(message, context = {}) ⇒ Object
- #error(message, context = {}) ⇒ Object
- #fatal(message, context = {}) ⇒ Object
- #info(message, context = {}) ⇒ Object
-
#initialize(output = $stdout, level: :info, format: :json) ⇒ AdvancedLogger
constructor
A new instance of AdvancedLogger.
- #log_ai_processing(feature, result, duration: nil) ⇒ Object
- #log_error(error, context = {}) ⇒ Object
- #log_request(env, duration: nil, status: nil) ⇒ Object
- #warn(message, context = {}) ⇒ Object
Constructor Details
#initialize(output = $stdout, level: :info, format: :json) ⇒ AdvancedLogger
Returns a new instance of AdvancedLogger.
22 23 24 25 26 27 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 22 def initialize(output = $stdout, level: :info, format: :json) @logger = ::Logger.new(output) @logger.level = LOG_LEVELS[level] || ::Logger::INFO @format = format @logger.formatter = method(:format_message) end |
Class Method Details
.instance ⇒ Object
18 19 20 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 18 def self.instance @instance ||= new end |
Instance Method Details
#debug(message, context = {}) ⇒ Object
29 30 31 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 29 def debug(, context = {}) log(:debug, , context) end |
#error(message, context = {}) ⇒ Object
41 42 43 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 41 def error(, context = {}) log(:error, , context) end |
#fatal(message, context = {}) ⇒ Object
45 46 47 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 45 def fatal(, context = {}) log(:fatal, , context) end |
#info(message, context = {}) ⇒ Object
33 34 35 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 33 def info(, context = {}) log(:info, , context) end |
#log_ai_processing(feature, result, duration: nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 63 def log_ai_processing(feature, result, duration: nil) context = { feature: feature, action: result[:action], confidence: result[:confidence], duration_ms: duration ? (duration * 1000).round(2) : nil, provider: result[:provider] }.compact info("AI Processing", context) end |
#log_error(error, context = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 75 def log_error(error, context = {}) error_context = { error_class: error.class.name, error_message: error., backtrace: error.backtrace&.first(5) }.merge(context) error("Application Error", error_context) end |
#log_request(env, duration: nil, status: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 49 def log_request(env, duration: nil, status: nil) context = { method: env['REQUEST_METHOD'], path: env['PATH_INFO'], query: env['QUERY_STRING'], user_agent: env['HTTP_USER_AGENT'], remote_ip: env['REMOTE_ADDR'], duration_ms: duration ? (duration * 1000).round(2) : nil, status: status }.compact info("HTTP Request", context) end |
#warn(message, context = {}) ⇒ Object
37 38 39 |
# File 'lib/rack/ai/utils/enhanced_logger.rb', line 37 def warn(, context = {}) log(:warn, , context) end |