Created
October 19, 2015 13:08
-
-
Save kares/0448608ee67790eb641f to your computer and use it in GitHub Desktop.
Logger::Formatter aware of Thread.current for JRuby
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
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