Class: Doing::LogAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/doing/log_adapter.rb

Overview

Log adapter

Constant Summary collapse

TOPIC_WIDTH =
12
LOG_LEVELS =
{
  debug: ::Logger::DEBUG,
  info: ::Logger::INFO,
  warn: ::Logger::WARN,
  error: ::Logger::ERROR
}.freeze
COUNT_KEYS =
%i[
  added_tags
  removed_tags
  added
  updated
  deleted
  completed
  archived
  moved
  completed_archived
  skipped
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level = :info) ⇒ LogAdapter

Create a new instance of a log writer

Parameters:

  • level (optional, symbol) (defaults to: :info)

    the log level

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.

#logdev=(value) ⇒ Object (writeonly)

Sets the attribute logdev

Parameters:

  • value

    the value to set the attribute logdev to.

#max_length=(value) ⇒ Object (writeonly)

Sets the attribute max_length

Parameters:

  • value

    the value to set the attribute max_length to.

#messagesObject (readonly)

Returns the value of attribute messages.

#resultsObject (readonly)

Returns the value of attribute results.

Instance Method Details

#abort_with(topic, message = nil, &block) ⇒ Object

Print an error message and immediately abort the process

Parameters:

  • topic

    the topic of the message, e.g. "Configuration file", "Deprecation", etc.

  • message (defaults to: nil)

    the message detail (can be omitted)

Returns:

  • nothing

#adjust_verbosity(options = {}) ⇒ Object

#count(key, level: :info, count: 1, tag: nil, message: nil) ⇒ Object

Raises:

  • (ArgumentError)

#debug(topic, message = nil, &block) ⇒ Object

Print a debug message

Parameters:

  • topic

    the topic of the message

  • message (defaults to: nil)

    the message detail

Returns:

  • nothing

#error(topic, message = nil, &block) ⇒ Object

Print an error message

Parameters:

  • topic

    the topic of the message, e.g. "Configuration file", "Deprecation", etc.

  • message (defaults to: nil)

    the message detail

Returns:

  • nothing

#formatted_topic(topic, colon: false) ⇒ Object

Format the topic

Parameters:

  • topic

    the topic of the message, e.g. "Configuration file", "Deprecation", etc.

  • colon (defaults to: false)

    Separate with a colon?

Returns:

  • the formatted topic statement

#info(topic, message = nil, &block) ⇒ Object

Print a message

Parameters:

  • topic

    the topic of the message, e.g. "Configuration file", "Deprecation", etc.

  • message (defaults to: nil)

    the message detail

Returns:

  • nothing

#log_level=(level = 'info') ⇒ Object

Set the log level on the writer

Parameters:

  • level (symbol) (defaults to: 'info')

    the log level

Returns:

  • nothing

#log_now(level, topic, message = nil, &block) ⇒ Object

Log to console immediately instead of writing messages on exit

Parameters:

  • level (Symbol)

    The level

  • topic (String)

    The topic or full message

  • message (String) (defaults to: nil)

    The message (optional)

  • block

    a block containing the message (optional)

#output_resultsObject

Output registers based on log level

Returns:

  • nothing

#warn(topic, message = nil, &block) ⇒ Object

Print a message

Parameters:

  • topic

    the topic of the message, e.g. "Configuration file", "Deprecation", etc.

  • message (defaults to: nil)

    the message detail

Returns:

  • nothing

#write(level_of_message, topic, message = nil, &block) ⇒ Boolean

Log a message.

Parameters:

  • level_of_message (Symbol)

    the Symbol level of message, one of :debug, :info, :warn, :error

  • topic (String)

    the String topic or full message

  • message (String) (defaults to: nil)

    the String message (optional)

  • block

    a block containing the message (optional)

Returns:

  • (Boolean)

    false if the message was not written