-
Notifications
You must be signed in to change notification settings - Fork 6
Logging in tim
Logging is extremely useful for debugging, both in development and in production environments. Patches submitted to Tim should contain a reasonable amount of logging. Logging will be used to locate errors, bugs in the code and for tracing the route through the code.
Tim uses the Ruby standard logger.
Rails makes a logger available in pretty much anything that inherits from a Rails class. i.e. ActiveRecord::Base, ActiveRecord::Controller. You can use this via
class Foo < ActiveRecord::Base
def bar
logger.debug "Processing Foo.bar"
end
end
For classes that do not inherit from Rails you can still use the helper method, but as a class method of Rails or you can use the contstant.
class Foo
def bar
Rails.logger.debug "Processing Foo.bar"
RAILS_DEFAULT_LOGGER.debug "Processing Foo.bar"
end
end
You should always log exception that are not propogated up and not expected. See: Exception Handling in Tim guide for more info
Lifted straight from Wiki:
Level Description OFF The highest possible rank and is intended to turn off logging. FATAL Severe errors that cause premature termination. Expect these to be immediately visible on a status console. ERROR Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. WARN Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console. INFO Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. DEBUG Detailed information on the flow through the system. Expect these to be written to logs only. TRACE Most detailed information. Expect these to be written to logs only. Since version 1.2.12.