Created
March 22, 2012 05:42
-
-
Save rondale-sc/2156472 to your computer and use it in GitHub Desktop.
an-introduction-to-loggin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ gem install logging | |
| # Successfully installed logging-1.6.1 | |
| # 1 gem installed | |
| # Building YARD (yri) index for logging-1.6.1... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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