Python logging

Just been reworking some code for a friend of mine - which needs to have quite a large amount of logging info. This I have rather painfully been doing in a PERL-eque way.... which in Python looks horrible.

Enter Logging

Logging

Its been around for ever .... but I have never used it (hangs head in shame).....

Use it !!

import logging
__author__ = 'tim'

if __name__ == "__main__":
  logging.basicConfig(level=logging.INFO)
  logger = logging.getLogger(__name__)
  logger.debug('Starting')
  my_sub_class=Really_USE_LOGGING()

If you are using Sub-classes ....

Then place this at the head of the sub/class

import logging
logger = logging.getLogger(__name__)

And then log away....

Log Files/roll-over

All possible - just change the handler in the logger initialization.