Skip to content

Instantly share code, notes, and snippets.

@rondale-sc
Created March 22, 2012 05:42
Show Gist options
  • Select an option

  • Save rondale-sc/2156472 to your computer and use it in GitHub Desktop.

Select an option

Save rondale-sc/2156472 to your computer and use it in GitHub Desktop.
an-introduction-to-loggin
$ gem install logging
# Successfully installed logging-1.6.1
# 1 gem installed
# Building YARD (yri) index for logging-1.6.1...
require 'logging'
Logging.logger.root.level = :warn
Logging.logger.root.appenders = Logging.appenders.stdout
log1 = Logging.logger['log1']
log2 = Logging.logger['log2']
log2.level = :debug
log1.info "This will not be shown."
log2.info "This will be shown."
require 'logging'
log1 = Logging.logger['log1']
log1.add_appenders(
Logging.appenders.stdout,
Logging.appenders.file('example.log')
)
log1.level = :info
log1.debug "this debug message will not be output by the logger"
log1.info "just some friendly advice"
require 'logging'
Logging.logger.root.appenders = Logging.appenders.stdout
Logging.logger.root.level = :info
class Foo
attr_reader :log
def initialize; @log = Logging.logger[self]; end
end
class Foo::Bar
attr_reader :log
def initialize; @log = Logging.logger[self]; end
end
foo = Foo.new.log
bar = Foo::Bar.new.log
# you'll notice in these log messages that the logger names were taken
# from the class names of the Foo and Foo::Bar instances
foo.info 'this message came from Foo'
bar.warn 'this is a warning from Foo::Bar'
gem 'logging-rails', :require => 'logging/rails'
rails generate logging:install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment