Module: Roda::RodaPlugins::EnhancedLogger
- Defined in:
- lib/roda/plugins/enhanced_logger.rb
Overview
The enhanced_logger plugin provides a coloured, single line log entry for requests in a Roda application.
Some interesting pieces of the log entry include which line matched the request, any time incurred by Sequel DB queries, and the remaining path that might have not been matched.
It’s mostly suitable in development but would likely be fine in production.
Constant Summary collapse
- DEFAULTS =
{ db: nil, log_time: false, trace_missed: true, trace_all: false, filtered_params: %w[password password_confirmation _csrf], handlers: [:console] }.freeze
Class Method Summary collapse
Class Method Details
.configure(app, opts = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/roda/plugins/enhanced_logger.rb', line 43 def self.configure(app, opts = {}) = DEFAULTS.merge(opts) logger = TTY::Logger.new { |config| config.handlers = [:handlers] config.output = .fetch(:output) { $stdout } config. = [:data, :time] if [:log_time] config.filters.data = [:filtered_params].map(&:to_s) config.filters.mask = "<FILTERED>" } root = Pathname(app.opts[:root] || Dir.pwd) db = [:db] || (defined?(DB) && DB) db&.extension :enhanced_logger app.match_hook do callee = caller_locations.find { |location| location.path.start_with?(root.to_s) } @_enhanced_logger_instance.add_match(callee) end app.before do @_enhanced_logger_instance = Roda::EnhancedLogger::Instance.new(logger, env, object_id, root, [:filter]) end app.after do |status, _| @_enhanced_logger_instance.add( status, request, ([:trace_missed] && status == 404) || [:trace_all] ) @_enhanced_logger_instance.drain @_enhanced_logger_instance.reset end end |
.load_dependencies(app, _opts = {}) ⇒ Object
38 39 40 41 |
# File 'lib/roda/plugins/enhanced_logger.rb', line 38 def self.load_dependencies(app, _opts = {}) app.plugin :hooks app.plugin :match_hook end |