Module: Postburner::Logging
Overview
Concern providing logging and exception tracking for Postburner jobs.
Provides methods for adding timestamped log entries and tracking exceptions in the job’s PostgreSQL audit trail. All logs are stored in JSONB arrays with timestamps, levels, and elapsed time tracking.
Instance Method Summary collapse
-
#log(message, options = {}) ⇒ Array<Array>
Appends a log message to the job’s logs array.
-
#log!(message, options = {}) ⇒ void
Appends a log message and immediately persists to database.
-
#log_exception(exception) ⇒ Array<Array>
Tracks an exception in the job’s errata array.
-
#log_exception!(exception) ⇒ void
Tracks an exception and immediately persists to database.
Instance Method Details
#log(message, options = {}) ⇒ Array<Array>
Invalid log levels are coerced to :error
Appends a log message to the job’s logs array.
Adds timestamped log entry to in-memory logs array with bkid, level, message, and elapsed time. Does NOT persist to database immediately. Use #log! to persist immediately.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/concerns/postburner/logging.rb', line 121 def log(, ={}) [:level] ||= :info [:level] = :error unless LOG_LEVELS.member?([:level]) self.logs << [ Time.current, # time { bkid: self.bkid, level: [:level], # level message: , # message elapsed: self.elapsed_ms, # ms from start } ] end |
#log!(message, options = {}) ⇒ void
This method returns an undefined value.
Appends a log message and immediately persists to database.
Calls #log to append message, then persists logs array to database. Use this for important log messages that should be saved immediately.
154 155 156 157 |
# File 'app/concerns/postburner/logging.rb', line 154 def log!(, ={}) self.log(, ) self.update_column :logs, self.logs end |
#log_exception(exception) ⇒ Array<Array>
Tracks an exception in the job’s errata array.
Appends exception details to the in-memory errata array with timestamp, class, message, and backtrace. Does NOT persist to database immediately. Use #log_exception! to persist immediately.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/concerns/postburner/logging.rb', line 62 def log_exception(exception) self.errata << [ Time.current, { bkid: self.bkid, class: exception.class, message: exception., backtrace: exception.backtrace, } ] end |
#log_exception!(exception) ⇒ void
This method returns an undefined value.
Tracks an exception and immediately persists to database.
Calls #log_exception to append exception details, then persists both errata and error_count to database via #persist_metadata!.
93 94 95 96 |
# File 'app/concerns/postburner/logging.rb', line 93 def log_exception!(exception) self.log_exception(exception) self. end |