Package: rusty-logger
Rusty LoggerSimple, opinionated and blazingly fast python logging.Rusty-Loggeris a thin python wrapper forRust'stracinglibrary that provides amostlydrop-in replacement forpythonsdefault logging.Table of contentsSupported configurationConstraintsAdditional metadataCode examplesAdditional examplesPerformanceContributingSupported ConfigurationArgDescriptionDefaultstdoutLog to stdoutTruestderrLog to stderrFalselevelLevel to logINFOapp_envApplication environment (APP_ENV env var)developmentlock_guardWhether to lock logger to current contextFalsethread_idWhether to display the thread idFalsecolorWhether to enable ansi coloring of logs for standard loggerFalsetime_formatCustom time format for logger[year]-[month]-[day]T[hour repr:24]:[minute]:[second]::[subsecond digits:4]json_configJsonConigNonejson_config.flattenWhether to flatten any passed fieldsTruefile_configLogFileConfigNonefile_config.filenameFilename for loglog/logs.logfile_config.rotateFile rotation specification.daily,hourly,minutelyorneverneverConstraintsTime is currently limited to UTC; however, you can customize time format to your liking using thetime_formatarg. Please refer to (time docs)[https://time-rs.github.io/book/api/format-description.html] for formatting guidelines. In addition, becauseRusty-LoggercallsRustdirectly, 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 thecontributingguide.In addition,Rusty-Loggeris amostlydrop-in replacement, meaning that you may need to make some minor changes to your existing code. For example,Rusty-Loggerdoes not support current python lazy formatting (e.g.logger.info("Number: %s", 10)). Instead,Rusty-Loggeruses Rust's default bracket ({}) formatting.# This is not supportedlogger.info("Number:%s",10)# This is supportedlogger.info("Number:{}",10)Show Me The Code!Basic Usagefromrusty_loggerimportLoggerlogger=Logger.get_logger(__file__)logger.info("Loggy McLogface")output2023-10-18T00:11:43::3194INFOLoggyMcLogfaceapp_env="development"name="your_file.py"JSONfromrusty_loggerimportLogger,LogConfig,JsonConfiglogger=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 filefromrusty_loggerimportLogger,LogConfig,JsonConfig,LogLevel,LogFileConfiglogger=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 fromlog/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 oncefromrusty_loggerimportLogger,LogConfig,JsonConfig,LogMetadata,LogLevel,LogFileConfiglogger=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 examplesFor additional examples, please see theexamplesdirectory which contains timed example of vanilla logger vsRusty-Logger,python-json-loggervsRusty-Loggeras well as a multi-worker API example.PerformanceWhy would we do this when python logging is fine? Because we wanted something faster :smile:. From our own benchmarks,Rusty-Loggertends to be ~4xfaster than vanilla python logging and ~8xfaster than vanillaJSONlogging. 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:.ContributingWhileRusty-Loggeris 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 thecontributingguide.Thank You!!! :heart: :heart: :heart: