Skip to content

Instantly share code, notes, and snippets.

@kares
Created October 19, 2015 13:08
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 kares/0448608ee67790eb641f to your computer and use it in GitHub Desktop.
Save kares/0448608ee67790eb641f to your computer and use it in GitHub Desktop.
Logger::Formatter aware of Thread.current for JRuby
require 'jruby'
class CurrentThreadAwareFormatter < Logger::Formatter
FORMAT = "%s [%5s] {%s} -- %s\n".freeze
def call(severity, time, progname, msg)
thread = Thread.current
thread_id = JRuby.reference(thread).getNativeThread.to_s
thread_id << ' ' << ( thread[:name] || thread.to_s )
FORMAT % [format_datetime(time), severity, thread_id, msg2str(msg)]
end
end
# ...
logger.formatter = CurrentThreadAwareFormatter.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment