0

I want to create a wrapper for python logger that will allow a config file to be loaded internally by the wrapper class. We have quite a large library and are looking to enforce this policy across any modules that are developed with minimal lines of code for dependancies.

import logging
import logging.config

class Log:

     file = "/path/to/logging.conf"

     def __init__(self,name):
            logging.config.fileConfig(self.file)
            self.l = logger.getLogger(name)

     def warn(...):

     ....

Instantiation would then be

import log

...

l = log.log(__name__)

l.info("Something happened")

Is this the best way to wrap the logging class or is there a better way?

sakurashinken
  • 3,940
  • 8
  • 34
  • 67
  • Why not use a function that reads the file (can be a constant, or a default parameter value), and returns the logger. So basically, turn `__init__` into a standalone function. Or just use two lines in your main code, and you don't even need to use a separate function or the import statement. It feels like you're making things more difficult than they have to be. –  Jun 22 '16 at 02:05
  • [Check this out](http://stackoverflow.com/questions/12980512/custom-logger-class-and-correct-line-number-function-name-in-log) if it helps, here similar solution is provided. – Indra Uprade Jun 22 '16 at 02:12

0 Answers0