Skip to main content

python logging library

Project description

tinylogging

GitHub License GitHub commit activity PyPI - Downloads PyPI - Version PyPI - Python Version Checks Documentation

Installation

pip install tinylogging

Usage

New logger

from tinylogging import Logger, Level

logger = Logger(name="my_logger", level=Level.DEBUG)

Logging messages

logger.info("This is an info message.")
logger.error("This is an error message.")
logger.debug("This is a debug message.")

Logging to a file

from tinylogging import FileHandler

file_handler = FileHandler(file_name="app.log", level=Level.WARNING)
logger.handlers.add(file_handler)

logger.warning("This warning will be logged to both console and file.")

Custom formatting

from tinylogging import Formatter

formatter = Formatter(template="{time} - {name} - {level} - {message}", colorize=False)
logger = Logger(name="custom_logger", formatter=formatter)
logger.info("This log message uses a custom format.")

Disabling logging

logger.disable()
logger.info("This message will not be logged.")
logger.enable()

Async support

import asyncio
from tinylogging import AsyncLogger, AsyncFileHandler


async def main():
    logger = AsyncLogger(name="async_logger")

    file_handler = AsyncFileHandler(file_name="app.log")
    logger.handlers.add(file_handler)

    await logger.info("This is an info message.")
    await logger.error("This is an error message.")
    await logger.debug("This is a debug message.")


if __name__ == "__main__":
    asyncio.run(main)

License

This project is licensed under the MIT License.

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

tinylogging-5.0.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

tinylogging-5.0.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file tinylogging-5.0.1.tar.gz.

File metadata

  • Download URL: tinylogging-5.0.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.12.10-arch1-1

File hashes

Hashes for tinylogging-5.0.1.tar.gz
Algorithm Hash digest
SHA256 38e5bd5f66d8786c2da364847dac126fab56e5d512a6d07d99c047d91ada0b76
MD5 e809621d13c04ca712280112758df81f
BLAKE2b-256 35786a71bc7ab1e47ca5637ad3a728997e5cf55672e4c8a9b696060a0f7aab0c

See more details on using hashes here.

File details

Details for the file tinylogging-5.0.1-py3-none-any.whl.

File metadata

  • Download URL: tinylogging-5.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.12.10-arch1-1

File hashes

Hashes for tinylogging-5.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8716ff56030ef528e7ebeab91f0fa4844a156d984cef184961106b90b0351544
MD5 fcbeeb8ef6a613f98213f68730a1e17a
BLAKE2b-256 f1e9411d9128f792390d46a6f74bb818961faf0603419415da87a55c21fb953e

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