Module: RDF::Util::Logger

Included in:
JSON::LD::API, JSON::LD::Context, JSON::LD::Writer, JSON::Reader, Microdata::Expansion::Rule, Microdata::Reader, N3::Algebra::Formula, N3::Algebra::List::Append, N3::Algebra::List::In, N3::Algebra::List::Last, N3::Algebra::Log::Implies, N3::Algebra::Math::AbsoluteValue, N3::Algebra::Math::Difference, N3::Algebra::Math::EqualTo, N3::Algebra::Math::Exponentiation, N3::Algebra::Math::GreaterThan, N3::Algebra::Math::IntegerQuotient, N3::Algebra::Math::LessThan, N3::Algebra::Math::MemberCount, N3::Algebra::Math::Negation, N3::Algebra::Math::NotEqualTo, N3::Algebra::Math::NotGreaterThan, N3::Algebra::Math::NotLessThan, N3::Algebra::Math::Product, N3::Algebra::Math::Quotient, N3::Algebra::Math::Remainder, N3::Algebra::Math::Rounded, N3::Algebra::Math::Sum, N3::Algebra::Str::Concatenation, N3::Algebra::Str::Contains, N3::Algebra::Str::ContainsIgnoringCase, N3::Algebra::Str::EndsWith, N3::Algebra::Str::EqualIgnoringCase, N3::Algebra::Str::Format, N3::Algebra::Str::GreaterThan, N3::Algebra::Str::LessThan, N3::Algebra::Str::Matches, N3::Algebra::Str::NotEqualIgnoringCase, N3::Algebra::Str::NotGreaterThan, N3::Algebra::Str::NotLessThan, N3::Algebra::Str::NotMatches, N3::Algebra::Str::Replace, N3::Algebra::Str::Scrape, N3::Algebra::Str::StartsWith, N3::Reader, N3::Reasoner, N3::Writer, NTriples::Reader, NTriples::Writer, Normalize::URDNA2015, Normalize::URDNA2015::NormalizationState, RDFXML::Reader, RDFXML::Writer, RDFa::Context, RDFa::Reader, RDFa::Writer, Reader, Tabular::Metadata, Tabular::Metadata::DebugContext, Tabular::Reader, Turtle::Reader, Turtle::Writer, Vocabulary::Writer, Writer
Defined in:
vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/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.

Since:

  • 2.0.0

Defined Under Namespace

Modules: LoggerBehavior

Constant Summary collapse

IOWrapper =

The IOWrapper class is used to store per-logger state while wrapping an IO such as $stderr.

Since:

  • 2.0.0

DelegateClass(IO)

Instance Method Summary collapse

Instance Method Details

#log_debug(*args, **options, &block)

Debug message.

This method returns an undefined value.

Parameters:

Options Hash (**options):

  • :depth (Integer)

    Recursion depth for indenting output

  • :lineno (Integer)

    associated with message

  • :logger (Logger, #<<)

Yield Returns:

  • (String)

    added to message

Since:

  • 2.0.0



176
177
178
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 176

def log_debug(*args, level: :debug, **options, &block)
  logger_common(*args, level: level, **options, &block)
end

#log_depth(options) { ... } ⇒ Object #log_depthInteger

Overloads:

  • #log_depth(options) { ... } ⇒ Object

    Increase depth around a method invocation

    Parameters:

    Options Hash (options):

    • :depth (Integer)

      Additional recursion depth

    • :logger (Logger, #<<)

    Yields:

    • Yields with no arguments

    Yield Returns:

    • (Object)

      returns the result of yielding

    Returns:

  • #log_depthInteger

    Return the current log depth

    Returns:

Since:

  • 2.0.0



194
195
196
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 194

def log_depth(**options, &block)
  self.logger(options).log_depth(&block)
end

#log_error(*args, **options, &block)

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.

This method returns an undefined value.

Parameters:

Options Hash (**options):

  • :depth (Integer)

    Recursion depth for indenting output

  • level (:fatal, :error, :warn, :info, :debug) — default: :<<
  • :lineno (Integer)

    associated with message

  • :logger (Logger, #<<)
  • :exception, (Class) — default: StandardError

    Exception class used for raising error

Yield Returns:

  • (String)

    added to message

Raises:

  • Raises the provided exception class using the first element from args as the message component, if :exception option is provided.

Raises:

  • (options[:exception])

Since:

  • 2.0.0



86
87
88
89
90
91
92
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 86

def log_error(*args, level: :error, **options, &block)
  logger = self.logger(options)
  return if logger.recovering
  logger.recovering = true
  logger_common(*args, level: level, **options, &block)
  raise options[:exception], args.first if options[:exception]
end

#log_fatal(*args, **options, &block)

Used for fatal errors where processing cannot continue. If logger is not configured, it logs to $stderr.

This method returns an undefined value.

Parameters:

Options Hash (**options):

  • :depth (Integer)

    Recursion depth for indenting output

  • :lineno (Integer)

    associated with message

  • :logger (Logger, #<<)
  • :exception, (Class) — default: StandardError

    Exception class used for raising error

Yield Returns:

  • (String)

    added to message

Raises:

  • Raises the provided exception class using the first element from args as the message component.

Raises:

  • (options.fetch(:exception, StandardError))

Since:

  • 2.0.0



61
62
63
64
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 61

def log_fatal(*args, level: :fatal, **options, &block)
  logger_common(*args, "Called from #{Gem.location_of_caller.join(':')}", level: level, **options, &block)
  raise options.fetch(:exception, StandardError), args.first
end

#log_info(*args, **options, &block)

Informational message.

This method returns an undefined value.

Parameters:

Options Hash (**options):

  • :depth (Integer)

    Recursion depth for indenting output

  • :lineno (Integer)

    associated with message

  • :logger (Logger, #<<)

Yield Returns:

  • (String)

    added to message

Since:

  • 2.0.0



158
159
160
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 158

def log_info(*args, level: :info, **options, &block)
  logger_common(*args, level: level, **options, &block)
end

#log_recover(*args, **options, &block)

Recovers from an error condition. If args are passed, sent as an informational message

As a side-effect of clearing @logger_in_error.

This method returns an undefined value.

Parameters:

Options Hash (**options):

  • :depth (Integer)

    Recursion depth for indenting output

  • :lineno (Integer)

    associated with message

  • :logger (Logger, #<<)

Yield Returns:

  • (String)

    added to message

Since:

  • 2.0.0



137
138
139
140
141
142
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 137

def log_recover(*args, level: :info, **options, &block)
  logger = self.logger(options)
  logger.recovering = false
  return if args.empty? && !block_given?
  logger_common(*args, level: level, **options, &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.

Parameters:

Options Hash (**options):

Returns:

  • (Boolean)

Since:

  • 2.0.0



98
99
100
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 98

def log_recovering?(**options)
  self.logger(options).recovering
end

#log_statistics(**options) ⇒ Hash{Symbol => Integer}

Number of times logger has been called at each level

Parameters:

Options Hash (**options):

Returns:

Since:

  • 2.0.0



40
41
42
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 40

def log_statistics(**options)
  logger(options).log_statistics
end

#log_warn(*args, **options, &block)

Warning message.

This method returns an undefined value.

Parameters:

Options Hash (**options):

  • :depth (Integer)

    Recursion depth for indenting output

  • level (:fatal, :error, :warn, :info, :debug) — default: :<<
  • :lineno (Integer)

    associated with message

  • :logger (Logger, #<<)

Yield Returns:

  • (String)

    added to message

Since:

  • 2.0.0



117
118
119
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 117

def log_warn(*args, level: :warn, **options, &block)
  logger_common(*args, level: level, **options, &block)
end

#logger(**options) ⇒ Logger, ...

Logger instance, found using options[:logger], @logger, or @options[:logger]

Parameters:

Options Hash (**options):

Returns:

Since:

  • 2.0.0



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-96fc834d6b23/lib/rdf/util/logger.rb', line 20

def logger(**options)
  logger = options.fetch(:logger, @logger)
  logger = @options[:logger] if logger.nil? && @options
  if logger.nil?
    # Unless otherwise specified, use $stderr
    logger = (@options || options)[:logger] = IOWrapper.new($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 || 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