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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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