Last active
November 28, 2018 15:31
-
-
Save ryanwood/41c55feba11b41511a577e94ce2dda16 to your computer and use it in GitHub Desktop.
Revisions
-
ryanwood revised this gist
Nov 28, 2018 . 2 changed files with 5 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # So we can log to STDOUT and a file at once. ;) class MultiIO def initialize(*targets) @targets = targets end 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,11 @@ require 'multi_io' def logger @logger ||= begin log_file = File.open("my_log_file.log", "a") target = MultiIO.new(STDOUT, log_file) Logger.new(target) end end # Use -
ryanwood created this gist
Nov 28, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ # So we can log to STDOUT and a file at once. ;) class MultiLogger def initialize(*targets) @targets = targets end def write(*args) @targets.each {|t| t.write(*args)} end def close @targets.each(&:close) end end 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ require 'multi_logger' def logger target = if DEBUG STDOUT else log_file = File.open("my_log_file.log", "a") MultiIO.new(STDOUT, log_file) end @logger ||= Logger.new(target) end # Use logger.debug("Would have run: #{sql}") logger.info('Checkpoint!')