Created
March 16, 2015 22:27
-
-
Save cwimmer/04d292635026cb008d7d to your computer and use it in GitHub Desktop.
Emulate log4j with Ruby Logger
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
#!/usr/bin/env ruby | |
require 'logger' | |
hostname = `hostname`.chop | |
file = File.open("/var/log/test-#{hostname}.log", File::WRONLY | File::APPEND | File::CREAT) | |
log = Logger.new(file) | |
log.level = Logger::INFO | |
log.formatter = proc do |severity, datetime, progname, msg| | |
"#{datetime.strftime('%Y-%m-%d %H:%M:%S,%3N')} #{severity} myproc: #{msg}\n" | |
end | |
log.info("Testing") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment