Skip to content
Donovan Keme edited this page Nov 19, 2015 · 16 revisions

By default, Celluloid will log any errors and backtraces from any crashing actors to STDOUT. However, if you wish you can use any logger which is duck typed with the standard Ruby Logger API (i.e. it implements the #error method). For example, if you're using Celluloid within a Rails application, you'll probably want to do:

Celluloid.logger = Rails.logger

The logger class you specify must be thread-safe, although with a logging API about the worst you have to worry about with thread safety bugs is out-of-order messages in the log.

You can also disable logging entirely:

Celluloid.logger = nil

Or log to a file:

require 'logger'
Celluloid.logger = ::Logger.new("mylog.log")

Logging within actors

Want to log stuff within actors? You can include Celluloid::Internals::Logger in your Celluloid-based classes:

class MyActor
  include Celluloid
  include Celluloid::Internals::Logger

  def initialize
    # This is the same as calling Celluloid::Logger.info
    info "Starting up..."
  end
end

It is duck-typed to the Rails logger and can respond to info, debug, warn, and error.

Clone this wiki locally