I installed a library that has a custom logging handler in the following form:
class LibraryCustomHandler(logging.handlers.RotatingFileHandler):
# Other LibraryCustomHandler methods
def format(self, record):
message = super(LibraryCustomHandler, self).format(record)
return library_function(record, message)
# Other LibraryCustomHandler methods
Note: library_function()
is a function and not a method of LibraryCustomHandler
.
I want a different library_function()
. So, in this case I normally create a subclass of the class I want to change:
class MyCustomHandler(path.to.LibraryCustomHandler):
def format(self, record):
message = super(MyCustomHandler, self).format(record)
return my_function(record, message)
But here the super
statement will also call the library_function()
from LibraryCustomHandler.format()
, which I don't want.
Right now, my working solution is:
class MyCustomHandler(path.to.LibraryCustomHandler):
def format(self, record):
message = logging.handlers.RotatingFileHandler.format(self, record)
return my_function(record, message)
I was wondering if there is a more pythonic or correct way of calling the super of super basically.