Class: OnlinePayments::SDK::Logging::RubyCommunicatorLogger
- Inherits:
-
CommunicatorLogger
- Object
- CommunicatorLogger
- OnlinePayments::SDK::Logging::RubyCommunicatorLogger
- Defined in:
- lib/onlinepayments/sdk/logging/ruby_communicator_logger.rb
Overview
Logging class that Logs messages and errors to a logger. Errors can be logged at a separate level compared to regular messages.
Class Method Summary collapse
-
.create_logfile(filename) ⇒ Object
Opens or creates a new file in write-only mode with filename.
-
.open_logfile(filename) ⇒ Object
Opens or creates a new file in write-only mode with filename.
Instance Method Summary collapse
-
#initialize(logger, log_level, error_level = false) ⇒ RubyCommunicatorLogger
constructor
Creates a new RubyCommunicatorLogger instance.
-
#log(msg, thrown = nil) ⇒ Object
Logs a single error or non-error message to the logger.
Constructor Details
#initialize(logger, log_level, error_level = false) ⇒ RubyCommunicatorLogger
Creates a new RubyCommunicatorLogger instance.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/onlinepayments/sdk/logging/ruby_communicator_logger.rb', line 15 def initialize(logger, log_level, error_level = false) # implement the interface error_level ||= log_level raise ArgumentError unless logger raise ArgumentError unless log_level raise ArgumentError unless error_level @logger = logger @log_level = log_level @errorLevel = error_level end |
Class Method Details
.create_logfile(filename) ⇒ Object
Opens or creates a new file in write-only mode with filename.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/onlinepayments/sdk/logging/ruby_communicator_logger.rb', line 38 def self.create_logfile(filename) logdev = begin open(filename, (File::WRONLY | File::APPEND | File::CREAT | File::EXCL)) rescue Errno::EEXIST # file is created by another process open_logfile(filename) end logdev.sync = true logdev end |
.open_logfile(filename) ⇒ Object
Opens or creates a new file in write-only mode with filename.
50 51 52 53 54 |
# File 'lib/onlinepayments/sdk/logging/ruby_communicator_logger.rb', line 50 def self.open_logfile(filename) open(filename, (File::WRONLY | File::APPEND)) rescue Errno::ENOENT create_logfile(filename) end |
Instance Method Details
#log(msg, thrown = nil) ⇒ Object
Logs a single error or non-error message to the logger.
28 29 30 31 32 33 34 35 |
# File 'lib/onlinepayments/sdk/logging/ruby_communicator_logger.rb', line 28 def log(msg, thrown = nil) # use Ruby Logger if thrown @logger.log(@errorLevel) { msg + $RS + thrown.to_s + $RS + thrown.backtrace.join($RS) } else @logger.log(@log_level, msg) end end |