Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rusty-logger

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rusty-logger

Super fast logging for python

  • 0.3.0
  • PyPI
  • Socket score

Maintainers
1

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

ArgDescriptionDefault
stdoutLog to stdoutTrue
stderrLog to stderrFalse
levelLevel to logINFO
app_envApplication environment (APP_ENV env var)development
lock_guardWhether to lock logger to current contextFalse
thread_idWhether to display the thread idFalse
colorWhether to enable ansi coloring of logs for standard loggerFalse
time_formatCustom time format for logger[year]-[month]-[day]T[hour repr:24]:[minute]:[second]::[subsecond digits:4]
json_configJsonConigNone
json_config.flattenWhether to flatten any passed fieldsTrue
file_configLogFileConfigNone
file_config.filenameFilename for loglog/logs.log
file_config.rotateFile rotation specification. daily, hourly, minutely or nevernever

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:

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc