Module: Celluloid::Internals::Logger

Defined in:
lib/celluloid/internals/logger.rb

Defined Under Namespace

Classes: WithBacktrace

Class Method Summary collapse

Class Method Details

.crash(string, exception) ⇒ Object

Handle a crash



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/celluloid/internals/logger.rb', line 65

def crash(string, exception)
  if Celluloid.log_actor_crashes
    string << "\n" << format_exception(exception)
    error string
  end

  @exception_handlers.each do |handler|
    begin
      handler.call(exception)
    rescue => ex
      error "EXCEPTION HANDLER CRASHED:\n" << format_exception(ex)
    end
  end
end

.debug(string) ⇒ Object

Send a debug message



42
43
44
45
46
47
# File 'lib/celluloid/internals/logger.rb', line 42

def debug(string)
  # !!! DO NOT INTRODUCE ADDITIONAL GLOBAL VARIABLES !!!
  # rubocop:disable Style/GlobalVars
  Celluloid.logger.debug(string) if Celluloid.logger && $CELLULOID_DEBUG
  # rubocop:enable Style/GlobalVars
end

.deprecate(message) ⇒ Object

Note a deprecation



81
82
83
84
# File 'lib/celluloid/internals/logger.rb', line 81

def deprecate(message)
  trace = caller.join("\n\t")
  warn "DEPRECATION WARNING: #{message}\n\t#{trace}"
end

.error(string) ⇒ Object

Send an error message



60
61
62
# File 'lib/celluloid/internals/logger.rb', line 60

def error(string)
  Celluloid.logger.error(string) if Celluloid.logger
end

.exception_handler(&block) ⇒ Object

Define an exception handler NOTE: These should be defined at application start time



88
89
90
91
# File 'lib/celluloid/internals/logger.rb', line 88

def exception_handler(&block)
  @exception_handlers << block
  nil
end

.format_exception(exception) ⇒ Object

Format an exception message



94
95
96
97
98
99
100
101
# File 'lib/celluloid/internals/logger.rb', line 94

def format_exception(exception)
  str = "#{exception.class}: #{exception}\n\t"
  str << if exception.backtrace
           exception.backtrace.join("\n\t")
         else
           "EMPTY BACKTRACE\n\t"
         end
end

.info(string) ⇒ Object

Send a info message



50
51
52
# File 'lib/celluloid/internals/logger.rb', line 50

def info(string)
  Celluloid.logger.info(string) if Celluloid.logger
end

.warn(string) ⇒ Object

Send a warning message



55
56
57
# File 'lib/celluloid/internals/logger.rb', line 55

def warn(string)
  Celluloid.logger.warn(string) if Celluloid.logger
end

.with_backtrace(backtrace) {|WithBacktrace.new(backtrace)| ... } ⇒ Object

Yields:



37
38
39
# File 'lib/celluloid/internals/logger.rb', line 37

def with_backtrace(backtrace)
  yield WithBacktrace.new(backtrace) if Celluloid.logger
end