Skip to main content

Logging for Data Pipelines

This library simplifies the logging setup process for new data pipelines, eliminating the need to repeatedly look up logger configurations.

Installation

Install the library via pip:

pip install log4data

Usage

To start using the library, simply import it in your script, and use the default configuration if you don't want to manually configure the logger.

import src.log4data.main as l4d
import logging as lg


if __name__ == "__main__":
    l4d.default_setup_logger()
    lg.info("Setup complete")

With just a few lines of code, you can set up effective logging. This will generate a log like this:

2024-07-03 00:00:00,000 - root - INFO - We are logging!

A more advanced use of the library is parametrize the file name or the logging level like this:

# main.py
import log4data as l4d
import logging as lg


if __name__ == "__main__":
    args = l4d.set_log_args(return_args=True)
    l4d.setup_logger_from_args(args)

    lg.info("Setup complete")

And then call python:

python main.py -lglv debug -lgfn etl.log

Finally, @inject_logger is a decorator to automatically add a logger to a function, named after that function. This is used like this:

# main.py
import argparse
import logging as lg
import log4data as l4d


@l4d.inject_logger
def my_data_processing_function(data, logger=None):
    logger.info(f"Processing data: {data}")
    print(data)
    return data


if __name__ == "__main__":
    # parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("-d", "--data", type=str, default="sample data")
    l4d.set_log_args(parser)
    args = parser.parse_args()

    # Configure logging
    l4d.setup_logger_from_args(args)

    # Call the function without providing the logger manually
    my_data_processing_function(args.data)

Then, calling this:

python main.py -d "Hello log for data."

Results in this log:

2024-07-03 00:00:00,000 - my_data_processing_function - INFO - Processing data: Hello log for data.

Contributing

This is a small project developed for my team and me, and while major upgrades are not planned, we welcome pull requests. If you encounter bugs or wish to suggest new features, please initiate a discussion by opening an issue.

License

This repository is under the MIT license.

Metadata

Release files for log4data 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for log4data 0.1.3
File Size Uploaded
log4data-0.1.3.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for log4data 0.1.3
File Interpreter ABI Platform
log4data-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / log4data-0.1.3.tar.gz

Download URL log4data-0.1.3.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
49dd30960dd8b9a955cacea3305a5ef0f8be3f5d60d0bbb5f8318ec4876c86a2
BLAKE2b-256 checksum
How to use checksums
6342e544f176c105c1edbdb1dbef7f8f25ac8c86bde0a758ea5e78d4bc71de3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / log4data-0.1.3-py3-none-any.whl

Download URL log4data-0.1.3-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83099e6367644d01de8b1961d8b06ed74aadd28fa887b0a4ba2ff6e1a50373c9
BLAKE2b-256 checksum
How to use checksums
0e625d5ca495ac9b9baf5d5c59d88e3b68e35f00189d2823540bc6ca9e681d79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page