Skip to content

Instantly share code, notes, and snippets.

@mghaught
Created January 20, 2015 20:28
Show Gist options
  • Save mghaught/662e9ac357037199dc7e to your computer and use it in GitHub Desktop.
Save mghaught/662e9ac357037199dc7e to your computer and use it in GitHub Desktop.

What is logging?

Taking output from a program and writing it to the end of a file (or other IO)

Why should you use this?

Easy way to track output from a running program, especially handy for long running processes like web servers

puts vs logger

Looking at logs

cat, less, grep

tail -f tail -500 less

Implementation/libraries:

Logger - Ruby stdlib class ActiveSupport extends it via Rails.logger

Logging gem

great, more robust replacement

Levels of logging

:debug, :info, :warn, :error, :fatal, :unknown 0, 1, 2, 3, 4, 5 default is debug

Changing level

config.log_level = :warn (in application.rb or environment initializers) Rails.logger.level = 0

Cost of logging

watch out for disk space rake log:clear log rotation logrotate SyslogLogger.new

Heroku and logging

Not like other environments since no long term storage. Does offer short-term logging, also add-ons for better logging support

heroku logs -t Papertrail add-on Logentries add-on

@TwP
Copy link

TwP commented Jan 20, 2015

There is a logging-rails gem which provides a generator for inserting logging into a rails application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment