Skip to main content

An EASY TO USE function decorator for advanced logging of function execution, including arguments, return values, and execution time.

Project description

logf

the @logf() decorator i previously had as part of the myfuncs pip package, decided to make it standalone pip package this is the repo for it

Usage

Here is a brief guide on how to use the logfunc module.

Installation

First, you need to install the logfunc package. This can be done through pip:

pip install myfuncs

Importing

Once the package is installed, you can import the logf function from the logfunc module:

from logfunc import logf

Logging Function Execution

The logf function is a decorator that you can apply to any function you want to log:

from logfunc import logf

@logf()
def my_function(a, b):
    return a + b

In the example above, logf() is used to wrap my_function. When my_function is called, it logs the function name, arguments, return value, and execution time.

Customize Logging

The logf function allows you to customize your logging:

  • You can set the log level with the level parameter.
  • Use log_args and log_return parameters to choose whether to log the arguments and the return value of the function.
  • max_str_len parameter allows you to set the maximum length of the logged arguments and return values.
  • You can choose whether to measure and log the function execution time with the measure_time parameter.

Here is an example:

from logfunc import logf

@logf(level='INFO', log_args=False, log_return=True, max_str_len=500, measure_time=True)
def my_function(a, b):
    return a + b

In this example, the function logs at the 'INFO' level, it doesn't log the function arguments, it logs the return value, trims logged strings to 500 characters, and it measures and logs the execution time.

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

logfunc-1.0.3.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

logfunc-1.0.3-py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 3

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