Module: RDF::Util::Logger::LoggerBehavior

Defined in:
lib/rdf/util/logger.rb

Overview

Module which is mixed-in to found logger to provide statistics and depth behavior

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Give Logger like behavior to non-logger objects

Since:

  • 2.0.0



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/rdf/util/logger.rb', line 273

def method_missing(method, *args)
  case method.to_sym
  when :fatal, :error, :warn, :info, :debug
    if self.respond_to?(:write)
      self.write "#{method.to_s.upcase} #{(args.join(": "))}\n"
    elsif self.respond_to?(:<<)
      self << "#{method.to_s.upcase} #{args.join(": ")}"
    else
      # Silently eat the message
    end
  when :level, :sev_threshold then 2
  else
    super
  end
end

Instance Attribute Details

#recoveringObject

Since:

  • 2.0.0



240
241
242
# File 'lib/rdf/util/logger.rb', line 240

def recovering
  @recovering
end

Instance Method Details

#log_depth(depth: 1, **options) { ... } ⇒ Object #log_depthInteger

Overloads:

  • #log_depth(depth: 1, **options) { ... } ⇒ Object

    Increase depth around a method invocation

    Parameters:

    • depth (Integer) (defaults to: 1)

      (1) recursion depth

    • options (Hash{Symbol})

      (@options || {})

    Options Hash (**options):

    Yields:

    • Yields with no arguments

    Yield Returns:

    • (Object)

      returns the result of yielding

    Returns:

    • (Object)
  • #log_depthInteger

    # Return the current log depth

    Returns:

    • (Integer)

Since:

  • 2.0.0



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/rdf/util/logger.rb', line 260

def log_depth(depth: 1, **options)
  @log_depth ||= 0
  if block_given?
    @log_depth += depth
    yield
  else
    @log_depth
  end
ensure
  @log_depth -= depth if block_given?
end

#log_statisticsObject

Since:

  • 2.0.0



242
243
244
# File 'lib/rdf/util/logger.rb', line 242

def log_statistics
  @logger_statistics ||= {}
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 2.0.0



289
290
291
292
293
294
# File 'lib/rdf/util/logger.rb', line 289

def respond_to_missing?(name, include_private = false)
  return true if 
    %i(fatal error warn info debug level sev_threshold)
    .include?(name.to_sym)
  super
end