Skip to main content

Logcat style log library

Project description

Logcatter 🐱

See logcatter from PyPI

Brings the familiar convenience and readability of Android's Logcat to your Python projects.

Tired of complex logger configurations? Logcatter lets you use intuitive methods like Log.d() and Log.i() right away. It automatically tags logs with the calling filename, dramatically speeding up your debugging workflow.

✨ Key Features

  • ☕ Android Logcat Style: Get beautiful, easy-to-read logs formatted as yyyy-MM-dd HH:mm:ss.SSS [D/tag] message.
  • 🏷️ Automatic Tagging: The name of the source file (main.py) that calls the log is automatically used as the tag, so you can instantly identify the origin of a log.
  • 🎨 Colored Output: Log levels (Debug, Info, Warning, Error) are color-coded for enhanced visual recognition.
  • 🚀 Concise API: Use intuitive methods nearly identical to the Android Log class: Log.d(), Log.i(), Log.w(), and Log.e().
  • 🔧 Zero Configuration: Works right out of the box after installation with no extra setup required.

📦 Installation

pip install logcatter

🚀 Quick Start

Just import the Log class into your project and call Log.init() first and Log.dispose() last of your code.

from logcatter import Log

Log.init()

Log.d("This is log!!")
Log.set_level(Log.WARNING)  # Hide DEBUG, INFO level logs
Log.i("This is info!!")  # You cannot see this because you set the minimum level `WARNING`
Log.e("ERROR!!!", e=ValueError())  # You can log the caught exception/error with argument `e`
Log.f("FATAL ERROR", s=True)  # You can log the stacktrace with flag `s`

Log.dispose()

Using with other's code

Some library or codes are using print(). And the format of Log is not applied basically to this. In this case, you can use Log.redirect as a context manager.

import sys
from logcatter import Log
Log.init()

with Log.redirect(
    stdout=Log.VERBOSE,
    stderr=None,
):
    print("Some message")
    sys.stderr.write("stderr message\n")

Log.dispose()

Output:

1970-01-01 00:00:00 000 [V/<stdin>] Some message
stderr message

stdout outputs (include print) will be handled a VERBOSE level. You can change this by parameter stdout. If the value is None, Log.redirect does not redirect stdout.

Same as stdout, you can redirect stderr outputs by parameter stderr. But the default value is None.

If internal print codes use CR (carriage return) to rewrite last line such as tqdm, the Log style will not be applied.

Save logs

You can save the log messages using just a single line.

from logcatter import Log
Log.init()

Log.i("This will not be saved")
Log.save("path of file")
Log.i("Message saved")

Log.dispose()

Saved log file:

Message saved

Multiprocessing

You can use Log in the multiprocessing with calling Log.init_worker(). (Don't forget the brackets!)

from logcatter import Log
import multiprocessing

Log.init()

with multiprocessing.Pool(processes=2, initializer=Log.init_worker()) as pool:
    Log.i("Some message")

Log.dispose()

For PyTorch

If you are using PyTorch, add Log.init_worker() to worker_init_fn. PyTorch uses complex IPC, so you specify logger initialization.

from logcatter import Log


train_loader = DataLoader(
    # Some codes
    worker_init_fn=Log.init_worker() 
)

💻 Output Example

Visual Studio Code

visual-studio-code-output-example

PyCharm

pycharm-output-exmaple

PowerShell 7 on Windows Terminal

pwsh7-wt-output-example

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

logcatter-0.3.5.tar.gz (112.6 kB view details)

Uploaded Source

Built Distribution

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

logcatter-0.3.5-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file logcatter-0.3.5.tar.gz.

File metadata

  • Download URL: logcatter-0.3.5.tar.gz
  • Upload date:
  • Size: 112.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for logcatter-0.3.5.tar.gz
Algorithm Hash digest
SHA256 37d3c83c90c6afb01e71d8a365f1edb7362991d7e34b4a3b2a79f5cfd0c6a930
MD5 6dba2ee76746fe0f1d0a336909e5cdd7
BLAKE2b-256 0754220713a35a5ff10bab021cfad259d4f27948bdfad524ca1cbf111b10d5c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for logcatter-0.3.5.tar.gz:

Publisher: python-publish.yml on RivMt/logcatter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file logcatter-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: logcatter-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for logcatter-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5d650f6fa58bfc5fb78da90b1d0ef77783fda987532bb662afec03d3cc443f38
MD5 9cf46c56f7242d63626321860cea25b6
BLAKE2b-256 25d5adee9a1c0cd998cd96538a901ca09f96f68b2f977d3a6518c50a888ee816

See more details on using hashes here.

Provenance

The following attestation bundles were made for logcatter-0.3.5-py3-none-any.whl:

Publisher: python-publish.yml on RivMt/logcatter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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