Skip to main content

A tool for converting f-strings in log functions to lazy-logging

Project description

Introduction

ALPHA SOFTWARE: Use at your own risk. Carefully vet the suggestions.

logzy is a linter / fixer that ensures Python log message arguments are in lazy-logging format. This is recommended so that arguments to the log messages are only rendered if they're emitted. Performance regressions can be occur if objects are being rendered even if the log message isn't being emitted.

For example:

import logging

log = logging.getLogger()

user = "root"

# Bad
log.warning(f"Login failed for {user}")

# Good
log.warning("Login failed for %s", user)

You may have seen tools like pylint complain about logging-fstring-interpolation, logging-format-interpolation, or logging-not-lazy.

Installation

pip install logzy

Usage

Since logzy only works on f-strings right now, you probably want to convert everything to an f-string first using a tool like flynt or pyupgrade

TODO

  • Make quote character intelligent
    • Check for any quote chars inside message string
    • Make the default configurable on the command line
  • logging.log(level, f"{message}")
  • Non f-string parameters to log functions (ie .format() or %)
  • Untested f-strings:
    • Multiline f-string
    • Nested f-string

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

logzy-0.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

logzy-0.1.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logzy-0.1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.7 Linux/5.19.16-200.fc36.x86_64

File hashes

Hashes for logzy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 14b4618656deeb7e5d1b7d568f28672b528b0851f41d3fd2950943917f516f2c
MD5 6169412c1f8c3574c82c25e455c5c5fd
BLAKE2b-256 1a4fac83f8959f67af6211758aa606fe1ed5c1a1bbaff34df0e8f86f585b8003

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logzy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.7 Linux/5.19.16-200.fc36.x86_64

File hashes

Hashes for logzy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c400e0b8633fa46ae45c48125230be5ec75cd247385e6e62ac1dbb713b5f8233
MD5 9247d41fbe2fd08d8901aee2477d6adc
BLAKE2b-256 a414bb9df4fb8e8049c80728193204c2df460d91fb8d38064c2528301b94fb2b

See more details on using hashes here.

Supported by

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