Class: Anywhere::Logger

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_levelObject



32
33
34
# File 'lib/anywhere/logger.rb', line 32

def log_level
  @log_level ||= ::Logger::INFO
end

#prefixObject

Returns the value of attribute prefix.



23
24
25
# File 'lib/anywhere/logger.rb', line 23

def prefix
  @prefix
end

Class Method Details

.mutexObject



27
28
29
# File 'lib/anywhere/logger.rb', line 27

def mutex
  @mutex ||= Mutex.new
end

Instance Method Details



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/anywhere/logger.rb', line 59

def print_with_prefix(message)
  out = [Time.now.utc.iso8601(6)]
  if prefix.is_a?(String)
    out << prefix
  elsif prefix.respond_to?(:call)
    out << prefix.call
  end
  out << message
  self.class.mutex.synchronize do
    stream.puts out.join(" ")
  end
end

#streamObject



44
45
46
# File 'lib/anywhere/logger.rb', line 44

def stream
  @attributes[:stream] ||= STDOUT
end