Skip to main content

Super fast logging for python

Project description

rusty logger logo

Lints-Tests codecov

Rusty Logger

Simple, opinionated and blazingly fast python logging. Rusty-Logger is a thin python wrapper for Rust's tracing library that provides a mostly drop-in replacement for pythons default logging.

Table of contents

Supported Configuration

Arg Description Default
stdout Log to stdout True
stderr Log to stderr False
level Level to log INFO
app_env Application environment (APP_ENV env var) development
lock_guard Whether to lock logger to current context False
thread_id Whether to display the thread id False
color Whether to enable ansi coloring of logs for standard logger False
time_format Custom time format for logger [year]-[month]-[day]T[hour repr:24]:[minute]:[second]::[subsecond digits:4]
json_config JsonConig None
json_config.flatten Whether to flatten any passed fields True
file_config LogFileConfig None
file_config.filename Filename for log log/logs.log
file_config.rotate File rotation specification. daily, hourly, minutely or never never

Constraints

Time is currently limited to UTC; however, you can customize time format to your liking using the time_format arg. Please refer to (time docs)[https://time-rs.github.io/book/api/format-description.html] for formatting guidelines. In addition, because Rusty-Logger calls Rust directly, it's not currently possible to pull the specific line number where logging takes place unless python is directly used (if you're even interested in this feature :smile:). If you'd like to see this feature implemented, and you want to contribute, please refer to the contributing guide.

In addition, Rusty-Logger is a mostly drop-in replacement, meaning that you may need to make some minor changes to your existing code. For example, Rusty-Logger does not support current python lazy formatting (e.g. logger.info("Number: %s", 10)). Instead, Rusty-Logger uses Rust's default bracket ({}) formatting.

# This is not supported
logger.info("Number: %s", 10)

# This is supported
logger.info("Number: {}", 10)

Show Me The Code!

Basic Usage

from rusty_logger import Logger

logger = Logger.get_logger(__file__)
logger.info("Loggy McLogface")

output

2023-10-18T00:11:43::3194  INFO Loggy McLogface app_env="development" name="your_file.py"

JSON

from rusty_logger import Logger, LogConfig, JsonConfig

logger = Logger.get_logger(__file__, LogConfig(json_config=JsonConfig()))
logger.info("Loggy McLogface logs")

output

{"timestamp":"2023-10-18T00:10:59::9732","level":"INFO","message":"Loggy McLogface logs","app_env":"development","name":"your_file.py"}

Log to file

from rusty_logger import Logger, LogConfig, JsonConfig, LogLevel, LogFileConfig

logger = Logger.get_logger(
    name=__file__,
    config=LogConfig(
        stdout=False,
        level=LogLevel.WARN,
        json_config=JsonConfig(),
        file_config=LogFileConfig(filename="logs/test.log"),
    ),
)
logger.warning("Loggy McLogface logs logs")

output from log/test.log

{"timestamp":"2023-10-18T00:10:10::9364","level":"WARN","message":"Loggy McLogface logs logs","app_env":"development","name":"your_file.py"}

Record multiple places at once

from rusty_logger import Logger, LogConfig, JsonConfig, LogMetadata, LogLevel, LogFileConfig

logger = Logger.get_logger(
    __file__,
    LogConfig(
        stdout=True,
        level=LogLevel.ERROR,
        json_config=JsonConfig(),
        file_config=LogFileConfig(filename="logs/test.log")
    ),
)
logger.error("Loggy McLogface logs logs that are logs")

output

{"timestamp":"2023-10-18T00:09:32::4053","level":"ERROR","message":"Loggy McLogface logs logs that are logs","app_env":"development","name":"your_file.py"}

Additional examples

For additional examples, please see the examples directory which contains timed example of vanilla logger vs Rusty-Logger, python-json-logger vs Rusty-Logger as well as a multi-worker API example.

Performance

Why would we do this when python logging is fine? Because we wanted something faster :smile:. From our own benchmarks, Rusty-Logger tends to be ~4x faster than vanilla python logging and ~8x faster than vanilla JSON logging. And while speed may not be mission critical for a few thousands logs, it can be for millions, which many companies deal with on a daily basis. Time is money and compute, and we want to save you both :moneybag: :computer:.

Contributing

While Rusty-Logger is production ready out of the box, it is still in it's infancy and is ripe for additional contributions. If you'd like to contribute, please see the contributing guide.

Thank You!!! :heart: :heart: :heart:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

rusty_logger-0.3.0-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ x86-64

rusty_logger-0.3.0-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

rusty_logger-0.3.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (993.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rusty_logger-0.3.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rusty_logger-0.3.0-pp310-pypy310_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rusty_logger-0.3.0-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (906.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.3.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (925.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rusty_logger-0.3.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl (996.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rusty_logger-0.3.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl (873.4 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rusty_logger-0.3.0-pp310-pypy310_pp73-macosx_10_12_x86_64.whl (926.7 kB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

rusty_logger-0.3.0-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ x86-64

rusty_logger-0.3.0-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

rusty_logger-0.3.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (993.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rusty_logger-0.3.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rusty_logger-0.3.0-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rusty_logger-0.3.0-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (907.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.3.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (925.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rusty_logger-0.3.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl (996.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rusty_logger-0.3.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl (873.4 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rusty_logger-0.3.0-pp39-pypy39_pp73-macosx_10_12_x86_64.whl (926.7 kB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

rusty_logger-0.3.0-pp38-pypy38_pp73-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ x86-64

rusty_logger-0.3.0-pp38-pypy38_pp73-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

rusty_logger-0.3.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (993.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rusty_logger-0.3.0-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rusty_logger-0.3.0-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.0 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rusty_logger-0.3.0-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (907.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.3.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (925.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rusty_logger-0.3.0-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.whl (996.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rusty_logger-0.3.0-pp38-pypy38_pp73-macosx_11_0_arm64.whl (873.1 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rusty_logger-0.3.0-pp38-pypy38_pp73-macosx_10_12_x86_64.whl (927.0 kB view hashes)

Uploaded PyPy macOS 10.12+ x86-64

rusty_logger-0.3.0-cp312-none-win_amd64.whl (934.1 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

rusty_logger-0.3.0-cp312-none-win32.whl (853.7 kB view hashes)

Uploaded CPython 3.12 Windows x86

rusty_logger-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

rusty_logger-0.3.0-cp312-cp312-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

rusty_logger-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (988.2 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

rusty_logger-0.3.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

rusty_logger-0.3.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.0 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

rusty_logger-0.3.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (902.7 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (920.8 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

rusty_logger-0.3.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (993.0 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.5+ i686

rusty_logger-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (871.9 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

rusty_logger-0.3.0-cp312-cp312-macosx_10_12_x86_64.whl (925.0 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

rusty_logger-0.3.0-cp311-none-win_amd64.whl (938.1 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

rusty_logger-0.3.0-cp311-none-win32.whl (860.8 kB view hashes)

Uploaded CPython 3.11 Windows x86

rusty_logger-0.3.0-cp311-cp311-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

rusty_logger-0.3.0-cp311-cp311-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

rusty_logger-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (992.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

rusty_logger-0.3.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

rusty_logger-0.3.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

rusty_logger-0.3.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (906.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (924.4 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

rusty_logger-0.3.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (996.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

rusty_logger-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (872.4 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rusty_logger-0.3.0-cp311-cp311-macosx_10_12_x86_64.whl (926.3 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

rusty_logger-0.3.0-cp310-none-win_amd64.whl (938.1 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

rusty_logger-0.3.0-cp310-none-win32.whl (860.8 kB view hashes)

Uploaded CPython 3.10 Windows x86

rusty_logger-0.3.0-cp310-cp310-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

rusty_logger-0.3.0-cp310-cp310-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

rusty_logger-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (992.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

rusty_logger-0.3.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

rusty_logger-0.3.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

rusty_logger-0.3.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (906.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (924.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

rusty_logger-0.3.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (996.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

rusty_logger-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (872.4 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rusty_logger-0.3.0-cp310-cp310-macosx_10_12_x86_64.whl (926.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

rusty_logger-0.3.0-cp39-none-win_amd64.whl (938.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

rusty_logger-0.3.0-cp39-none-win32.whl (861.0 kB view hashes)

Uploaded CPython 3.9 Windows x86

rusty_logger-0.3.0-cp39-cp39-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

rusty_logger-0.3.0-cp39-cp39-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

rusty_logger-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (992.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

rusty_logger-0.3.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

rusty_logger-0.3.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

rusty_logger-0.3.0-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (906.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (924.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

rusty_logger-0.3.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (996.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

rusty_logger-0.3.0-cp39-cp39-macosx_11_0_arm64.whl (872.6 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

rusty_logger-0.3.0-cp39-cp39-macosx_10_12_x86_64.whl (926.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.12+ x86-64

rusty_logger-0.3.0-cp38-none-win_amd64.whl (938.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

rusty_logger-0.3.0-cp38-none-win32.whl (861.2 kB view hashes)

Uploaded CPython 3.8 Windows x86

rusty_logger-0.3.0-cp38-cp38-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

rusty_logger-0.3.0-cp38-cp38-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

rusty_logger-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (992.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

rusty_logger-0.3.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.5 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

rusty_logger-0.3.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

rusty_logger-0.3.0-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (906.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (924.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

rusty_logger-0.3.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (996.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

rusty_logger-0.3.0-cp38-cp38-macosx_11_0_arm64.whl (872.4 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

rusty_logger-0.3.0-cp38-cp38-macosx_10_12_x86_64.whl (926.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.12+ x86-64

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