Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Python decorator function to track metadata on function calls

Project description

# Metadata for Functions
Python decorator function to track metadata on function calls

# Example
def self_mult(n):
return n*n

print(self_mult(10)) # => 100
print(self_mult.log_info()) # => {'time_started': 1422042033.971449, 'warnings': None, 'args': (10,), 'error_info': None, 'time_ended': 1422042034.171857, 'time_elapsed': 0.200408, 'return_value': 100, 'kwargs': None}

print(self_mult(15)) # => 225
print(self_mult.log_info()) # => {'time_started': 1422042034.172171, 'warnings': None, 'args': (15,), 'error_info': None, 'time_ended': 1422042034.373299, 'time_elapsed': 0.201128, 'return_value': 225, 'kwargs': None}

print(self_mult("foo")) # => None
print(self_mult.log_info()) # => {'time_started': 1422042034.373651, 'warnings': None, 'args': ('foo',), 'error_info': (<type 'exceptions.TypeError'>, TypeError("can't multiply sequence by non-int of type 'str'",), <traceback object at 0x10fcea098>), 'time_ended': 1422042034.574758, 'time_elapsed': 0.201107, 'return_value': None, 'kwargs': None}

# Usage
Decorate a function with `@meta_func()` passing the optional keyword argument ignore_errors = True/False. ignore_errors tells `@meta_func` whether or not to raise any exception your decorated function raises or to solely log to the error_info attribute.

# Compatibility
Tested compatible with Py2.7 and Py3, but this code is provided as is with no warranty or guarantee, implied or explicit.

# More Information
Please see my blog post here:

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
meta_func-0.1.3.tar.gz (2.4 kB) Copy SHA256 hash SHA256 Source None Mar 9, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page