Skip to main content

Advanced python logging decorators.

Project description

Have you ever wanted to have logging decorators for logging function calls and for automatic creation of logger object in class, based on class hierarchy.

If your answer is true, here is my implementation https://github.com/offlinehacker/PyLogDecorate. There is very nice option i’ve implemented called subdecorate, enabling for functions in derived classes being logged, even if decorator is only applied on base class function.

This logging decorator implementation can be easily extended.

  • Install:

    python setup.py install or easy_install PyLogDecorate.

  • Example code:

from log import LogCall, LogClass

@LogCall()
def test():
    print "x"

@LogClass({"subdecorate": True})
class test1(object):
    name="kekec"
    name2="kekec2"
    @LogCall({"subdecorate": True, "tracename": "tracetest", "traceattr": "name"})
    def test(self):
        pass

    @LogCall({"subdecorate": True, "tracename": "tracetest", "traceattr": "name2"})
    def test2(self):
        self.logger.debug("Inside base class!")

@LogClass()
class test2(test1):
    def __init__(self):
        pass

    def test(self):
        self.logger.debug("Inside funtion.")
        self.test2()

@LogClass()
class test3(test2):
    def __init__(self):
        pass

    def test(self):
        self.logger.debug("Inside funtion2.")
        self.test2()


test()
b=test3()
c=test2()
b.test()
c.test()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyLogDecorate-0.333.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file PyLogDecorate-0.333.tar.gz.

File metadata

File hashes

Hashes for PyLogDecorate-0.333.tar.gz
Algorithm Hash digest
SHA256 53eb35aa89596d68ae9feb392d62d437db9fb6fbdd34f5a5f5e6b17634b4c603
MD5 197e8053e8d3475f1ae0c28dbf185f59
BLAKE2b-256 548ee6d1a262f52128de9bf117fad68e12164a1d83de005010139c39f881ed03

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page