Class: Abstractive::Actor

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/abstractive/actor.rb

Instance Method Summary collapse

Instance Method Details

#console(message, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/abstractive/actor.rb', line 8

def console(message, options={})
  if @logger
    @logger.console(message, options.merge(local: true))
  else
    plain_output("#{mark}#{message}")
  end
rescue
  plain_output("#{mark}#{message}")
end

#debug(message) ⇒ Object



18
19
20
# File 'lib/abstractive/actor.rb', line 18

def debug(message)
  console(message, level: :debug)
end

#exception(ex, *args) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/abstractive/actor.rb', line 22

def exception(ex, *args)
  return @logger.exception(ex, *args) if @logger
  plain_output("(#{ex.class}) #{ex.message}: #{args.first}")
rescue
  plain_output("(#{ex.class}) #{ex.message}: #{args.first}")
ensure
  plain_output("(#{ex.class}) #{ex.message}: #{args.first}")
end

#markObject



41
42
43
44
45
# File 'lib/abstractive/actor.rb', line 41

def mark
  if @mark == true
    "#{self.class.name} > "
  end
end

#plain_output(message) ⇒ Object



31
32
33
34
35
# File 'lib/abstractive/actor.rb', line 31

def plain_output(message)
  message = "*, [#{Time.now.strftime('%FT%T.%L')}] #{mark}#{message}"
  STDERR.puts message
  STDOUT.puts message
end

#pretty_output(object) ⇒ Object



37
38
39
# File 'lib/abstractive/actor.rb', line 37

def pretty_output object
  puts JSON.pretty_generate(object)
end