Class: Rufio::Logger
- Inherits:
-
Object
- Object
- Rufio::Logger
- Defined in:
- lib/rufio/logger.rb
Overview
Unified logger for debug and error messages Only logs when BENIYA_DEBUG environment variable is set to ‘1’
Constant Summary collapse
- LOG_FILE =
File.join(Dir.home, '.rufio_debug.log')
- DEBUG =
Log levels
:debug- INFO =
:info- WARN =
:warn- ERROR =
:error
Class Method Summary collapse
-
.clear_log ⇒ Object
Clear the log file.
-
.debug(message, context: {}) ⇒ Object
Log a debug message with optional context.
-
.error(message, exception: nil, context: {}) ⇒ Object
Log an error message with optional exception.
-
.info(message, context: {}) ⇒ Object
Log an info message.
-
.warn(message, context: {}) ⇒ Object
Log a warning message.
Class Method Details
.clear_log ⇒ Object
Clear the log file
60 61 62 63 64 |
# File 'lib/rufio/logger.rb', line 60 def clear_log return unless debug_enabled? File.open(LOG_FILE, 'w') { |f| f.puts "=== Rufio Debug Log Cleared at #{Time.now} ===" } end |
.debug(message, context: {}) ⇒ Object
Log a debug message with optional context
19 20 21 22 23 |
# File 'lib/rufio/logger.rb', line 19 def debug(, context: {}) return unless debug_enabled? write_log(DEBUG, , context) end |
.error(message, exception: nil, context: {}) ⇒ Object
Log an error message with optional exception
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rufio/logger.rb', line 47 def error(, exception: nil, context: {}) return unless debug_enabled? full_context = context.dup if exception full_context[:exception] = exception. full_context[:backtrace] = exception.backtrace&.first(5) end write_log(ERROR, , full_context) end |
.info(message, context: {}) ⇒ Object
Log an info message
28 29 30 31 32 |
# File 'lib/rufio/logger.rb', line 28 def info(, context: {}) return unless debug_enabled? write_log(INFO, , context) end |
.warn(message, context: {}) ⇒ Object
Log a warning message
37 38 39 40 41 |
# File 'lib/rufio/logger.rb', line 37 def warn(, context: {}) return unless debug_enabled? write_log(WARN, , context) end |