Logs

jrochkind edited this page Oct 1, 2014 · 14 revisions

Like a typical rails app, Umlaut logs to the ./logs directory, in development.log or production.log etc, depending on what environment you are running under.

Checking for Errors

Rails logger (or any ruby Logger) can log messages with different severity levels: FATAL, ERROR, WARN, INFO, DEBUG.

The default Rails production environment log includes INFO lines for every request. It also includes FATAL lines for any unexpected exceptions (bugs).

In addition, Umlaut will log ERROR or WARN for any service errors -- which could be caused by a third party service being down or returning an expected result, or could be caused by a bug in Umlaut's service plugin code.

Unfortunately, Rails by default does not actually include the severity of logged messages in it's log file, doh.

You can install the Rails gem jrochkind wrote, https://github.com/jrochkind/formatted_rails_logger, to have Rails log with severity.

Then you might want to periodically grep your log file for ERROR|WARN|FATAL to see if there are any problems going on you should know about.

Turn off database logging in development

The database logging turned on in development is rather verbose. It's by default not present in a production environment, but sometimes you want to turn it off in development so you can examine the other logging, such as umlaut's own service logging.

Add this to an environment file, such as ./environments/development.rb

config.active_record.logger = nil

Rails 3.2 by default turned on 'auto explain logging for long queries'. However, this does not seem to work properly under Umlaut's multi-threaded use of ActiveRecord, and also seems to have a bug where it conflicts with disabling the AR log. So you may want to find and comment out this line in ./config/environments/development/rb, and will have to if you disable active_record_logger as above. Even if you leave AR logging on in general, my impression is that this feature produces false positives in Umlaut due to multi-threaded AR use, and is not useful.

#   config.active_record.auto_explain_threshold_in_seconds = 0.5

Service Errors reported in Web interface

If a service fails with an exception, it'll be listed in the 'errors' block in the lower right corner of the screen.

If you click on the tiny "[D]" link in the footer, it will toggle visible some formerly hidden debug info next to that error report. Looking something like, for example:

technical error information
NoMethodError
undefined method `inner_text' for nil:NilClass
dispatched service id: 1302

If you go directly into your database and look for the DispatchedService object with that id, you will generally find a stack trace and other info about the exception raised, and the status of the service execution.

select * from dispatched_services where id = 1302;

I am considering writing a web admin layer for viewing recent failed services with their context like this, mention if you are interested in seeing it (or writing it!).

Service Logging

Umlaut will log when each service wave (priority) begins and ends, and elapsed time, and how long each service within a wave takes to execute.

This can be useful for jrochkind trying to investigate Umlaut performance, or for you trying to figure out if you should arrange your services in waves differently for better overall responsiveness.

By default, this is only on in development, but you can turn it on or off altogether with Umlaut config (in UmlautController), log_service_timing [true|false].

It will be output with ansi terminal colors, as yellow, to make finding it in the logs easier -- by default only when Rails app standard config.colorize_logging is true, which is generally in development and not production.

SEE ALSO An interactive report of recent service errors, in Admin Functions

Ansi colors in logging

Umlaut logging uses ansi color sequences, which can make the log files easier to parse when scanning them in the terminal. But depending on your toolchain, you can wind up annoyingly seeing the escape sequences directly instead of colors, which is just a pain.

Umlaut respects rails config.colorize_logging (a Rails config value from Rails which hardly anything in Rails actually uses), just set config.colorize_logging = false in your ./config/application.rb, or a specific ./config/environments/ENV.rb` to turn off.

It probably ought to be false in production, which probably ought to be the Rails default but isn't, stick it in ./config/environments/production.rb. (Umlaut4 does this on app generation by default)