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
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 in many workflows it'll work out of the box with no code change needed. However, in cases of lazy logging through additional args, args are expected to already be formatted as a str and will not be formatted by Rusty-Logger as the rust logic expects a Vec<&str> for args. For example, the following will not work:

# This will fail
logger.info("Number: %s", 10)

# This will not fail
logger.info("Number: %s", str(10))

Additional Metadata

You may also pass additional metadata along with any logging messages via the LogMetadata class, which takes a Dict[str, str] as an argument.

Show Me The Code!

Basic Usage

from rusty_logger import Logger

logger = Logger.get_logger(__file__)
logger.info("his palms are sweaty")

output

2023-09-15T20:16:31.985449Z  INFO his palms are sweaty 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("knees weak")

output

{"timestamp":"2023-09-15T20:19:52.182299Z","level":"INFO","message":"knees weak","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("arms are heavy")

output from log/test.log

{"timestamp":"2023-09-15T20:23:37.461645Z","level":"WARN","message":"arms are heavy","app_env":"development","name":"your_file.py"}

Adding some metadata

from rusty_logger import Logger, LogConfig, JsonConfig, LogMetadata

logger = Logger.get_logger(__file__, LogConfig(json_config=JsonConfig()))
metadata = LogMetadata(data={"there's": "vomit"})
logger.info("on his sweater already", metadata=metadata)

output

{"timestamp":"2023-09-15T20:27:29.013887Z","level":"INFO","message":"on his sweater already","app_env":"development","name":"your_file.py","info":"{\"there's\": \"vomit\"}"}

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("MOM'S SPAGHETTI!")

output

{"timestamp":"2023-09-15T20:32:23.417027Z","level":"ERROR","message":"MOM'S SPAGHETTI!","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 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.1.3-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.1.3-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

rusty_logger-0.1.3-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (985.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rusty_logger-0.1.3-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rusty_logger-0.1.3-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.1.3-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (897.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.1.3-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (917.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rusty_logger-0.1.3-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl (960.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rusty_logger-0.1.3-pp310-pypy310_pp73-macosx_11_0_arm64.whl (864.8 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rusty_logger-0.1.3-pp310-pypy310_pp73-macosx_10_7_x86_64.whl (934.6 kB view hashes)

Uploaded PyPy macOS 10.7+ x86-64

rusty_logger-0.1.3-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.1.3-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

rusty_logger-0.1.3-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (985.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rusty_logger-0.1.3-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rusty_logger-0.1.3-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.1.3-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (896.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.1.3-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (917.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rusty_logger-0.1.3-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl (960.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rusty_logger-0.1.3-pp39-pypy39_pp73-macosx_11_0_arm64.whl (864.7 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rusty_logger-0.1.3-pp39-pypy39_pp73-macosx_10_7_x86_64.whl (934.6 kB view hashes)

Uploaded PyPy macOS 10.7+ x86-64

rusty_logger-0.1.3-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.1.3-pp38-pypy38_pp73-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy musllinux: musl 1.1+ ARM64

rusty_logger-0.1.3-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (984.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rusty_logger-0.1.3-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rusty_logger-0.1.3-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.1.3-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (896.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.1.3-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (917.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rusty_logger-0.1.3-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.whl (960.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

rusty_logger-0.1.3-pp38-pypy38_pp73-macosx_11_0_arm64.whl (864.7 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

rusty_logger-0.1.3-pp38-pypy38_pp73-macosx_10_7_x86_64.whl (935.0 kB view hashes)

Uploaded PyPy macOS 10.7+ x86-64

rusty_logger-0.1.3-cp311-none-win_amd64.whl (898.9 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

rusty_logger-0.1.3-cp311-none-win32.whl (814.7 kB view hashes)

Uploaded CPython 3.11 Windows x86

rusty_logger-0.1.3-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.1.3-cp311-cp311-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

rusty_logger-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (985.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

rusty_logger-0.1.3-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

rusty_logger-0.1.3-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.1.3-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (897.1 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (917.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

rusty_logger-0.1.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (960.4 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

rusty_logger-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (864.7 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rusty_logger-0.1.3-cp311-cp311-macosx_10_7_x86_64.whl (934.4 kB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

rusty_logger-0.1.3-cp310-none-win_amd64.whl (898.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

rusty_logger-0.1.3-cp310-none-win32.whl (814.7 kB view hashes)

Uploaded CPython 3.10 Windows x86

rusty_logger-0.1.3-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.1.3-cp310-cp310-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

rusty_logger-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (985.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

rusty_logger-0.1.3-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

rusty_logger-0.1.3-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.1.3-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (897.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (917.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

rusty_logger-0.1.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (960.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

rusty_logger-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (864.8 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rusty_logger-0.1.3-cp310-cp310-macosx_10_7_x86_64.whl (934.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

rusty_logger-0.1.3-cp39-none-win_amd64.whl (898.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

rusty_logger-0.1.3-cp39-none-win32.whl (814.9 kB view hashes)

Uploaded CPython 3.9 Windows x86

rusty_logger-0.1.3-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.1.3-cp39-cp39-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

rusty_logger-0.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (985.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

rusty_logger-0.1.3-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

rusty_logger-0.1.3-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.1.3-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (897.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.1.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (917.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

rusty_logger-0.1.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (960.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

rusty_logger-0.1.3-cp39-cp39-macosx_11_0_arm64.whl (864.9 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

rusty_logger-0.1.3-cp39-cp39-macosx_10_7_x86_64.whl (934.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

rusty_logger-0.1.3-cp38-none-win_amd64.whl (899.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

rusty_logger-0.1.3-cp38-none-win32.whl (814.9 kB view hashes)

Uploaded CPython 3.8 Windows x86

rusty_logger-0.1.3-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.1.3-cp38-cp38-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

rusty_logger-0.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (984.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

rusty_logger-0.1.3-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

rusty_logger-0.1.3-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.1.3-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (896.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

rusty_logger-0.1.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (917.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

rusty_logger-0.1.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (960.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

rusty_logger-0.1.3-cp38-cp38-macosx_11_0_arm64.whl (864.9 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

rusty_logger-0.1.3-cp38-cp38-macosx_10_7_x86_64.whl (934.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ 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