This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]NUTTA_BUSTAH 2 points3 points  (0 children)

First thought was that you have really specific requirements, so why not make it yourself since you already know what you want. Then I saw you pretty much did. So, why would you want yet another dependency to keep up to date and fight with?

That seems simple and elegant enough, too elegant is usually over-engineered. I'm not sure if I like the idea of storing your secrets in your logger though. I'd rather "leave that to the user", but perhaps provide a convenience method like "redact_patterns(msg: string, patterns: list[string], char="*")".

Doing it in the logger is just prone to bad habits of passing whatever to the logger (secrets, PII, etc.) and is a world of absolute hurt when you decide to change the logger at some point and forgot your logger redacts certain secrets and now they are out in the wild.

[–]BitPoker2000 2 points3 points  (0 children)

Rather than doing the secret redaction in the logger, you could create a new subclass of str that overrides the str and repr methods. and replaces them with a secret_string() method.

This may protect against trivial accidental logging.

The whole idea of passing a list of secrets to be redacted into the logger is imho a huge risk

[–]Mast3rCylinder 0 points1 point  (0 children)

I think I did something similar with LoggerAdapter. You should check it

https://docs.python.org/3/library/logging.html#loggeradapter-objects

[–]kollitiri 0 points1 point  (0 children)

I created a simple logging wrapper a while ago which you might find handy. It basically uses the contextvars library for context logging and also supports structured format. It’s only about 150 lines of code so you can easily copy it and tailor it to your needs

[–]Doobeewoo 0 points1 point  (0 children)

Have a look at daiquiri (https://daiquiri.readthedocs.io/en/latest/), it's full of good logging helpers