Skip to main content

Tasks Logger

Logo

Overview

tasks-logger is a versatile Python logging library designed to facilitate detailed and color-coded logging for applications that manage multiple tasks, such as those operating across various threads or processes. It extends the basic functionality of Python’s built-in logging module to include dynamic log levels, thread-safe output, conditional file logging, and vivid color outputs for better clarity and monitoring.

Check also tasks-loader

Table Of Contents

Features

  • Dynamic Log Levels: Easily define new log levels on the fly.
  • Color-coded Output: Enhance log visibility with configurable color outputs for each log level.
  • Conditional File Logging: Decide which log level messages are important enough to save to files.
  • Thread Safety: Ensure logs are thread-safe using locks to prevent text scrambling when used in multi-threaded applications.

Installation

Install tasks-logger via pip:

pip install tasks-logger

How It Works

tasks-logger utilizes the Colorama library to add color to log messages depending on their severity. You can set up different log levels and specify whether these should be output to the console, saved to a file, or both. The logger also supports dynamic addition of new log levels with specific properties.

Usage

Basic Setup

Here's how to set up and use the tasks-logger:

from tasks_logger import Logger

logger = Logger(level='INFO', file_level='ERROR', filename='app.log')
logger.info("This is an informational message.")
logger.error("This error message will also be saved to a file.")

Adding New Log Levels

You can add new log levels dynamically:

logger.add_level('VERBOSE', 15, Fore.LIGHTBLUE_EX)
logger.verbose("This is a verbose message with custom log level.")

Thread-Safe Logging

tasks-logger is designed to be safe for use in multi-threaded environments:

import threading

def task():
    logger.info("Log from a thread.")

thread = threading.Thread(target=task)
thread.start()
thread.join()

Conditional File Logging

Control which log levels are logged to files:

# Only ERROR and above levels will be saved to the file.
logger = Logger(level='DEBUG', file_level='ERROR', filename='important.log')
logger.debug("This message will not be logged in the file.")
logger.error("This error will be logged in the file.")

Example Application: Sneakers/Tickets Bot

Here is an example showing how tasks-logger might be used in a sneakers/tickets purchasing bot, which operates with multiple tasks:

class MyTask:
    def __init__(self, task_id: str, mail: str, ...):
        self.logger = Logger(
            level='INFO', 
            task_id=task_id,
            mail=mail,
            formatting="[{timestamp}] [{level}] ({task_id}) {mail} - {message}"
        )

Stay in touch with me

For any inquiries or further information, please reach out:

Feel free to contact for collaborations, questions, or feedback any of my projects.

Metadata

Release files for tasks-logger 0.1.0

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

Source distribution (sdist)

Source distribution for tasks-logger 0.1.0
File Size Uploaded Provenance Actions
tasks-logger-0.1.0.tar.gz 4.9 kB Without provenance Details for tasks-logger-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tasks-logger 0.1.0
File Interpreter ABI Platform Actions
tasks_logger-0.1.0-py3-none-any.whl Python 3 none any Details for tasks_logger-0.1.0-py3-none-any.whl

Total release size: 10.0 kB

Release files / tasks-logger-0.1.0.tar.gz

Download URL tasks-logger-0.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a6dba5c891f1063171806876170b343346f491d1b14ac83baafe00e8e63e2c06
BLAKE2b-256 checksum
How to use checksums
4b673388b1aaf18cd3ded5a9f8a331c5c89d64ef876f41d19c39b4a8d3f9dfe3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.0

Release files / tasks_logger-0.1.0-py3-none-any.whl

Download URL tasks_logger-0.1.0-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea4e35d66e921b5423c06980748e5ae7f7d1392b850a5c5f98fd72669474b101
BLAKE2b-256 checksum
How to use checksums
c58bc4c0bfaa0984811c2776f2ecacd3faf36bb4f0a1fe93ea7b93d906bf9fbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.0

Security for tasks-logger 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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