formatter.rb 790 B

1234567891011121314151617181920
  1. # This customization adds the id of the current Thread to all log lines.
  2. # It was introduced to make it more easy to follow the execution of tasks in the log in threaded processes.
  3. #
  4. # before:
  5. # D, [2018-11-20T16:35:03.483547 #72102] DEBUG -- : (0.5ms) SELECT COUNT(*) FROM "delayed_jobs"
  6. #
  7. # after:
  8. # D, [2018-11-20T16:35:03.483547 #72102-23423534] DEBUG -- : (0.5ms) SELECT COUNT(*) FROM "delayed_jobs"
  9. class Logger
  10. class Formatter
  11. # original: Format = "%s, [%s#%d] %5s -- %s: %s\n".freeze
  12. FORMAT_WITH_THREAD_ID = "%s, [%s#%d-%d] %5s -- %s: %s\n".freeze
  13. def call(severity, time, progname, msg)
  14. format(FORMAT_WITH_THREAD_ID, severity[0..0], format_datetime(time), Process.pid, Thread.current.object_id, severity, progname, msg2str(msg))
  15. end
  16. end
  17. end