Skip to main content

loggingontips is a library which makes logging flexible and easy to use without bothering about log management.

Project description

LoggingOnTips

loggingontips is a Python package that simplifies logging setup and configuration. It eliminates the need for manual handling by allowing users to configure various logging parameters effortlessly, such as log file names and file rotations based on timestamps, file size, or the number of logs.

Features

  • Customizable Logging: Set log file names and configure rotation settings with ease.
  • File Rotation:
    • By timestamp.
    • By file size. (By default)
    • By number of logs.
  • Synchronous Logging: Fully supported.
  • Thread Safe Logging: Fully supported.
  • Asynchronous Logging: Coming soon in future releases!

Installation

Install the package using pip:

pip install loggingontips

Usage

Creating a simple log file with a single log

from loggingontips.Logger import Logger
from loggingontips.LogLevels import LogLevel
logger=Logger()

def run():
    logger.log(LogLevel.INFO,'Is it working?')

if __name__=="__main__":
    run()

Simulation of file rotation after exceeding size limit

from loggingontips.Logger import Logger
from loggingontips.LogLevels import LogLevel
l1=Logger()
#In this case log file should be rotated as size limit is 4 MB and logs are of 16 MB+
def run():
    for i in range(10000000):
        l1.log(LogLevel.DEBUG,'Working?')

if __name__=="__main__":
    run()

Simulation of thread_safe_log() function [Should be called from threads]

import threading
import os
from loggingontips.LogLevels import LogLevel
from loggingontips.Logger import Logger


def test_thread_safe_log():
    log_file = "test_thread_safe_log.log"
    if os.path.exists(log_file):
        os.remove(log_file) 

    logger = Logger(log_file=log_file)

    def worker(thread_id):
        for i in range(100):
            logger.thread_safe_log(LogLevel.INFO, f"Thread-{thread_id} log message {i}")

    threads = []
    for thread_id in range(15):
        thread = threading.Thread(target=worker, args=(thread_id,))
        threads.append(thread)
        thread.start()

    for thread in threads:
        thread.join()

    logger.close()

if __name__ == "__main__":
    test_thread_safe_log()

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

loggingontips-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loggingontips-0.1.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file loggingontips-0.1.2.tar.gz.

File metadata

  • Download URL: loggingontips-0.1.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for loggingontips-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fe90986717bf7c6ac01a890adc71fefd89e30ad34a9bbcf1aa76c535d110d656
MD5 954fdb8ce61587a4914573ab8e036926
BLAKE2b-256 b41e24604bb3993adc54ce48e3695f006b517def432dff9dcf80e17f2bec0ba3

See more details on using hashes here.

File details

Details for the file loggingontips-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: loggingontips-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for loggingontips-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 03d4c78939a4a6eee7635894669855a0b9898bf7689e3ae38393ff9dcd25df97
MD5 fd139550e2f4a8be377e9dab6d526fc2
BLAKE2b-256 e910164f5206af3f21f0f6c9534c46d43a620b12a723579abf8010ab5cab0cb4

See more details on using hashes here.

Supported by

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