Skip to content

Instantly share code, notes, and snippets.

@cwimmer
Created March 16, 2015 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwimmer/04d292635026cb008d7d to your computer and use it in GitHub Desktop.
Save cwimmer/04d292635026cb008d7d to your computer and use it in GitHub Desktop.
Emulate log4j with Ruby Logger
#!/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