Class: NRSER::Log::Formatters::Mixin::Tokens

Inherits:
Array show all
Defined in:
lib/nrser/log/formatters/mixin.rb

Overview

Abstract base class for HeaderTokens and BodyTokens, instances of which are used by formatters that include NRSER::Log::Formatters::Mixin to configure what pieces of information make up the header and body sections of log messages that it formats.

Entries are SemanticLogger::Formatter::Default method names, which I’ve called “tokens”, and the order of the “tokens” dictates the order the results of those method calls will be joined to form the formatted message section.

Adding, removing and reordering tokens is used to control what elements appear and where in the formatted result.

Token arrays are mutable and meant to changed in place via Array#delete and friends.

Direct Known Subclasses

BodyTokens, HeaderTokens

Instance Method Summary collapse

Methods inherited from Array

#ellipsis, #extract!, #rest, #to_chainer, #to_digger, #to_message, #to_pair, #to_proc, #to_sender

Methods included from Ext::Tree

#each_branch, #leaves, #map_branches, #map_leaves, #map_tree

Constructor Details

#initialize(tokens = self.class::ALL) ⇒ Tokens

Create a new token array.

Parameters:

  • tokens (Array<#to_sym>) (defaults to: self.class::ALL)

    The token symbols to initialize the array with. Must be covetable to symbols (really, just pass symbols in the first place).



65
66
67
# File 'lib/nrser/log/formatters/mixin.rb', line 65

def initialize tokens = self.class::ALL
  super tokens.map( &:to_sym )
end

Instance Method Details

#reset!Tokens

Reset the array to be all the available tokens for the section in their original order.

**Mutates the array in place.**

Returns:



78
79
80
81
82
# File 'lib/nrser/log/formatters/mixin.rb', line 78

def reset!
  clear
  self.class::ALL.each { |token| self << token }
  self
end