Created
February 13, 2017 17:13
-
-
Save chris-roerig/86df195f64efa16c98c4e0fe381c4993 to your computer and use it in GitHub Desktop.
Log to a specific file in Rails
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
# Logs to the specified file in the Rails log folder | |
# | |
# Usage: | |
# LogTo.file("tracking-numbers").info "log some data" | |
# or | |
# logger = LogTo.file("tracking-numbers") | |
# logger.info "this is saved in my tracking-numbers log" | |
class LogTo | |
def self.file(name) | |
return Rails.logger if Rails.env.test? | |
Logger.new("#{Rails.root}/log/#{name}.log") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment