Skip to content

Instantly share code, notes, and snippets.

@radavis
Created February 12, 2018 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radavis/b6934b8e09df000fa86a15e6759e27f3 to your computer and use it in GitHub Desktop.
Save radavis/b6934b8e09df000fa86a15e6759e27f3 to your computer and use it in GitHub Desktop.

Logs

Log levels

From 0 to 5 in severity:

  • debug - for debugging purposes, only
  • info - an informative message
  • warn - this may or may not be an issue
  • error - this is an issue, but the application can continue running
  • fatal - this is and issue, and the application should halt
  • unknown - we don't know (?)

A corresponding Rails.logger.level method exists for each of these levels.

Logging important events in the application

When writing to the log, give the developer some "breadcrumbs" to follow. Specify the class name and method name that is writing to the log.

msg = "[#{self.class.name}##{__method__}] something important happened that we should log."
Rails.logger.info(msg)

If you are rescueing, it probably makes sense to log the error, as well.

begin
  # some code that might fail
rescue StandardError => err
  Rails.logger.error("[#{self.class.name}##{__method__}] raised an error.")
  Rails.logger.error(err)
  # handle the error
end

Download Logs from Production

$ scp -p ubuntu@wobbe.workbar.com:~/wobbe/current/log/* ~/path/to/wobbe/logs

Searching Logs

The following command will show you three lines before and three lines after any occurrence of ClassName.

$ cat production.log | grep -B 3 -A 3 "ClassName"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment