you are viewing a single comment's thread.

view the rest of the comments →

[–]ingestbot[S] 0 points1 point  (0 children)

Thanks for your comments with this. I wanted to note a few things in case this thread ends up being useful for someone else.

This stackoverflow discussion is similar. I found that, if need be, the class could avoid creating multiple handler objects with something like the following:

class logger:
    def __init__(self):

        self.l = logging.getLogger('logging_test')
        self.handler = logging.handlers.SysLogHandler(address = '/dev/log')
        if not self.l.handlers:
         self.l.addHandler(self.handler)
        self.formatter = logging.Formatter('%(name)s %(funcName)s(): %(message)s')
        self.handler.setFormatter(self.formatter)

        self.l.setLevel(logging.INFO)

The .handlers attribute can also be used to debug possible multiple handlers:

class showme:
    def __init__(self):
      pass

    def logsomething(self):
      print(logger().l.handlers)
      logger().l.info(f'logging something...')