A level group is a group of related levels that can be ordered and used in a log. A given log is always associated with exactly one group, which controls what levels are available for log entries.
Normally, you will use Sawmill::STANDARD_LEVELS, which defines levels corresponding to the ones available in the classic ruby logger class. However, this class is available to define custom level hierarchies.
Create a level group. You must provide a block that calls methods of Sawmill::LevelGroup::Builder to define the levels in the group.
# File lib/sawmill/level.rb, line 111 def initialize(&block_) @level_order = [] @level_names = {} @level_methods = {} @default = nil ::Blockenspiel.invoke(block_, Builder.new(self)) end
Return the length of the longest name in the group.
# File lib/sawmill/level.rb, line 148 def column_width @level_order.inject(0) do |width_, level_| w_ = level_.name.size w_ > width_ ? w_ : width_ end end
Return the default level, the one used when no level is specified.
# File lib/sawmill/level.rb, line 127 def default @default ||= highest end
Get a level in this group.
You may pass either an integer value, a level name, a level object, or nil. If you pass nil, the default level is returned. Otherwise, the level corresponding to the given parameter is returned. If no level in this group corresponds to the parameter, nil is returned.
# File lib/sawmill/level.rb, line 170 def get(name_) case name_ when ::Integer @level_order[name_] when Level @level_order[name_.value] == name_ ? name_ : nil when ::Symbol, ::String @level_names[name_.to_sym] when nil default else nil end end
Return the highest level in the group.
# File lib/sawmill/level.rb, line 141 def highest @level_order.last end
Look up a level by a logger method name.
# File lib/sawmill/level.rb, line 158 def lookup_method(method_name_) @level_methods[method_name_.to_sym] end
Return the lowest level in the group.
# File lib/sawmill/level.rb, line 134 def lowest @level_order.first end