1

How can I get the logging handler object instance(s) in django (>=1.3)? with standard python logging I instantiate the logger and then the handler:

h = logging.handlers.TimedRotatingFileHandler( FILE, 'D', 1)

I want h or the array of h's that django uses when i use its' LOGGING dict in settings.py. Any ideas?

yee379
  • 6,498
  • 10
  • 56
  • 101

1 Answers1

1

i was able to get all active handlers by:

import logging
h = []
for a in logging.root.handlers:
    h.append( a.stream )

(in the above i wanted to the file objects rather than the actual handlers themselves)

hope this helps someone!

yee379
  • 6,498
  • 10
  • 56
  • 101
  • This is old, but still useful. Thank you. However, looping is unnecessary. Use `from copy import deepcopy; h = deepcopy(logging.root.handlers)` instead. – Vedran Šego Nov 12 '22 at 13:09