Module: Spyt
- Defined in:
- lib/spyt.rb,
lib/spyt/config.rb,
lib/spyt/levels.rb,
lib/spyt/version.rb,
lib/spyt/loggable.rb,
lib/spyt/loggable/logger.rb
Overview
Spyt Module
Defined Under Namespace
Modules: Loggable
Constant Summary collapse
- CONFIG =
Configuration: Defines Spyt’s behavior.
{ # Output Stream out: $stdout, # Level lvl: :info }
- LEVELS =
Levels: Available Log Levels, mapped to numeric values.
{ debug: 2, info: 1, error: 0 }
- LEVEL_COLS =
Level Colors: When using Spiffup for colorization, this map defines which color corresponds to which level.
{ debug: :brown, info: :green, error: :red }
- VERSION =
Version
'1.1.0'
Class Method Summary collapse
-
.method_missing(name, *args) ⇒ Object
Generic Log Handler: Route log calls to each level.
-
.push(lvl, src, msg) ⇒ Object
Push Message: Writes a message msg from src as level lvl to the log.
Class Method Details
.method_missing(name, *args) ⇒ Object
Generic Log Handler: Route log calls to each level.
16 17 18 19 20 21 22 23 |
# File 'lib/spyt.rb', line 16 def self.method_missing name, *args # Fail on unknown Methods super unless LEVELS.include? name # Push Log (Level shortcuts) push name, args[0], args[1] end |
.push(lvl, src, msg) ⇒ Object
Push Message: Writes a message msg from src as level lvl to the log.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spyt.rb', line 30 def self.push lvl, src, msg # Check Level raise "Invalid Log Level [#{lvl.to_s.inspect.bred}] requested" unless LEVELS.include? lvl.to_sym # Check Level return unless LEVELS[lvl] <= LEVELS[CONFIG[:lvl]] # Ensure Lock is available @lock ||= Mutex.new # Synchronize @lock.synchronize do # Write & Flush CONFIG[:out] << "#{Time.now.to_s.blue} [#{lvl.to_s.send LEVEL_COLS[lvl.to_sym]}] #{src.bmagenta} :: #{msg}\n" CONFIG[:out].flush if CONFIG[:out].respond_to? :flush end end |