Class: Doing::Logger

Inherits:
Object show all
Defined in:
lib/doing/logger.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
  added_tags
  archived
  autotag
  completed
  completed_archived
  deleted
  moved
  removed_tags
  rotated
  skipped
  updated
  exported
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level = :info) ⇒ Logger

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 current log level (debug, info, warn, error)

#logdev=(value) ⇒ Object (writeonly)

Sets the log device

#max_length=(value) ⇒ Object (writeonly)

Max length of log messages (truncate in middle)

#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

#benchmark(key, state) ⇒ 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_benchmarksObject

#log_change(tags_added: [], tags_removed: [], count: 1, item: nil, single: false) ⇒ Object

#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

#restore_levelObject

Restore temporary level

#temp_level(level) ⇒ Object

Set log level temporarily

#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