Module: RDF::Util::Logger
- Included in:
- NTriples::Reader, NTriples::Writer, Reader, Vocabulary::Writer, Writer
- Defined in:
- lib/rdf/util/logger.rb
Overview
Helpers for logging errors, warnings and debug information.
Modules must provide ‘@logger`, which returns an instance of `Logger`, or something responding to `#<<`. Logger may also be specified using an `@options` hash containing a `:logger` entry.
Defined Under Namespace
Modules: LoggerBehavior
Instance Method Summary collapse
-
#log_debug(*args, options = {}, &block) ⇒ void
Debug message.
- #log_depth(options = {}, &block) ⇒ Object
-
#log_error(*args, options = {}, &block) ⇒ void
Used for non-fatal errors where processing can continue.
-
#log_fatal(*args, options = {}, &block) ⇒ void
Used for fatal errors where processing cannot continue.
-
#log_info(*args, options = {}, &block) ⇒ void
Informational message.
-
#log_recover(*args, options = {}, &block) ⇒ void
Recovers from an error condition.
-
#log_recovering?(options = {}) ⇒ Boolean
In recovery mode? When ‘log_error` is called, we enter recovery mode.
-
#log_statistics(options = {}) ⇒ Hash{Symbol => Integer}
Number of times logger has been called at each level.
-
#log_warn(*args, options = {}, &block) ⇒ void
Warning message.
- #logger(options = {}) ⇒ Logger, ...
Instance Method Details
#log_debug(*args, options = {}, &block) ⇒ void
Debug message.
172 173 174 175 |
# File 'lib/rdf/util/logger.rb', line 172 def log_debug(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} logger_common(*args, .merge(level: :debug), &block) end |
#log_depth(options) { ... } ⇒ Object #log_depth ⇒ Integer
191 192 193 |
# File 'lib/rdf/util/logger.rb', line 191 def log_depth( = {}, &block) self.logger().log_depth(&block) end |
#log_error(*args, options = {}, &block) ⇒ void
Used for non-fatal errors where processing can continue. If ‘logger` is not configured, it logs to `$stderr`.
As a side-effect of setting ‘@logger_in_error`, which will suppress further error messages until cleared using #log_recover.
82 83 84 85 86 87 88 89 |
# File 'lib/rdf/util/logger.rb', line 82 def log_error(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} logger = self.logger() return if logger.recovering logger.recovering = true logger_common(*args, .merge(level: :error), &block) raise [:exception], args.first if [:exception] end |
#log_fatal(*args, options = {}, &block) ⇒ void
Used for fatal errors where processing cannot continue. If ‘logger` is not configured, it logs to `$stderr`.
57 58 59 60 61 |
# File 'lib/rdf/util/logger.rb', line 57 def log_fatal(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} logger_common(*args, "Called from #{Gem.location_of_caller.join(':')}", .merge(level: :fatal), &block) raise .fetch(:exception, StandardError), args.first end |
#log_info(*args, options = {}, &block) ⇒ void
Informational message.
154 155 156 157 |
# File 'lib/rdf/util/logger.rb', line 154 def log_info(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} logger_common(*args, .merge(level: :info), &block) end |
#log_recover(*args, options = {}, &block) ⇒ void
Recovers from an error condition. If ‘args` are passed, sent as an informational message
As a side-effect of clearing ‘@logger_in_error`.
133 134 135 136 137 138 139 |
# File 'lib/rdf/util/logger.rb', line 133 def log_recover(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} logger = self.logger() logger.recovering = false return if args.empty? && !block_given? logger_common(*args, .merge(level: :info), &block) end |
#log_recovering?(options = {}) ⇒ Boolean
In recovery mode? When ‘log_error` is called, we enter recovery mode. This is cleared when `log_recover` is called.
95 96 97 |
# File 'lib/rdf/util/logger.rb', line 95 def log_recovering?( = {}) self.logger().recovering end |
#log_statistics(options = {}) ⇒ Hash{Symbol => Integer}
Number of times logger has been called at each level
36 37 38 |
# File 'lib/rdf/util/logger.rb', line 36 def log_statistics( = {}) logger().log_statistics end |
#log_warn(*args, options = {}, &block) ⇒ void
Warning message.
113 114 115 116 |
# File 'lib/rdf/util/logger.rb', line 113 def log_warn(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} logger_common(*args, .merge(level: :warn), &block) end |
#logger(options = {}) ⇒ Logger, ...
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rdf/util/logger.rb', line 16 def logger( = {}) logger = .fetch(:logger, @logger) logger = @options[:logger] if logger.nil? && @options if logger.nil? # Unless otherwise specified, use $stderr logger = (@options || )[:logger] = $stderr # Reset log_statistics so that it's not inherited across different instances logger.log_statistics.clear if logger.respond_to?(:log_statistics) end logger = (@options || )[:logger] = ::Logger.new(::File.open(::File::NULL, "w")) unless logger # Incase false was used, which is frozen logger.extend(LoggerBehavior) unless logger.is_a?(LoggerBehavior) logger end |