Class: Anywhere::Logger
- Inherits:
-
Object
- Object
- Anywhere::Logger
- Defined in:
- lib/anywhere/logger.rb
Constant Summary collapse
- LEVELS =
{ DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, FATAL: 4, UNKNOWN: 5 }
- COLORS =
{ 0 => "#6d6d6d", # 109, 109, 109 1 => "#227000", # 34, 112 2 => "#f79700", # 247, 151 3 => "#f00000", # 240, 0 }
Instance Attribute Summary collapse
- #log_level ⇒ Object
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Logger
constructor
A new instance of Logger.
- #print_with_prefix(message) ⇒ Object
- #stream ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Logger
Returns a new instance of Logger.
36 37 38 |
# File 'lib/anywhere/logger.rb', line 36 def initialize(attributes = {}) @attributes = attributes end |
Instance Attribute Details
#log_level ⇒ Object
32 33 34 |
# File 'lib/anywhere/logger.rb', line 32 def log_level @log_level ||= ::Logger::INFO end |
#prefix ⇒ Object
Returns the value of attribute prefix.
23 24 25 |
# File 'lib/anywhere/logger.rb', line 23 def prefix @prefix end |
Class Method Details
.mutex ⇒ Object
27 28 29 |
# File 'lib/anywhere/logger.rb', line 27 def mutex @mutex ||= Mutex.new end |
Instance Method Details
#print_with_prefix(message) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/anywhere/logger.rb', line 59 def print_with_prefix() out = [Time.now.utc.iso8601(6)] if prefix.is_a?(String) out << prefix elsif prefix.respond_to?(:call) out << prefix.call end out << self.class.mutex.synchronize do stream.puts out.join(" ") end end |
#stream ⇒ Object
44 45 46 |
# File 'lib/anywhere/logger.rb', line 44 def stream @attributes[:stream] ||= STDOUT end |