% crystal usage.cr
I, [2017-12-06 21:35:07 +0900 #8536] INFO -- : Hi stdout!
E, [2017-12-06 21:35:07 +0900 #8536] ERROR -- : Hi stdout, error!
% cat debug.log
D, [2017-12-06 21:35:07 +0900 #8536] DEBUG -- : Hi all!
I, [2017-12-06 21:35:07 +0900 #8536] INFO -- : Hi stdout!
E, [2017-12-06 21:35:07 +0900 #8536] ERROR -- : Hi stdout, error!
% cat error.log
E, [2017-12-06 21:35:07 +0900 #8536] ERROR -- : Hi stdout, error!
Last active
December 6, 2017 12:45
-
-
Save maiha/36417aba9a74a3995d9d72d78a4c6923 to your computer and use it in GitHub Desktop.
This file contains 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
class CompositeLogger | |
def initialize(@loggers : Array(Logger) = loggers) | |
end | |
macro method_missing(call) | |
@loggers.each do |logger| | |
logger.{{call}} | |
end | |
end | |
end |
This file contains 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
logger1 = Logger.new(File.open("debug.log", "w+")).tap(&.level = Logger::DEBUG) | |
logger2 = Logger.new(File.open("error.log", "w+")).tap(&.level = Logger::ERROR) | |
logger3 = Logger.new(STDOUT).tap(&.level = Logger::INFO) | |
logger = CompositeLogger.new([logger1, logger2, logger3]) | |
logger.debug "Hi all!" | |
logger.info "Hi stdout!" | |
logger.error "Hi stdout, error!" | |
# logger.debagu "..." # gives a compile error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment