PYHINTS Telegram 445
Python Hints
اینم یک مثال (شروع سطح سنیور کار با logging) مثال آخر. اولین نکته؛ environment = "production" خط ۷ تا ۱۸ من یک کلاس فلیتر تعریف کردم که قرار اگر توی لاگ رکورد چیزی به اسم phone وجود داشت بخش اول اون رو با * بپوشونه و بصورت دیفالت فقط ۴ رقم آخر رو نشون بده.…
بنابراین بجای کلید class از () استفاده میشه.
و همونطور که قبلا هم گفتم هر چیزی که بعد از این بیاد ورودی‌هایی هست که اون کلاس قبول می‌کنه؛ من اینجا گفتم اگر توی dev نبودم فقط ۴ کاراکتر آخر شماره تلفن رو نشون بده ولی اگر روی dev بودم ۱۰ تاش رو نشون بده.

حالا فقط کافیه filter ایی که تعریف کردم رو به هرکدوم از handler هایی که لازم هست پاس بدم که توی خط 57 دارم اینکار رو برای file handler انجام میدم.
سوال : چطوری phone رو به logRecord اضافه کنیم ؟
خط ۷۵ رو ببینید؛ وقتی یک کلیدی داریم که بصورت دیفالت روی logger تعریف نشده؛ راه قشنگش اینه که اون رو توی extra برای logger های مورد نظر ارسال کنیم:
logger.critical("Call meeeeeeee", extra={"phone": "09121212122"})
خروجی میشه چیزی که توی تصویر می‌بینید.
👍15❤‍🔥52🫡1



tgoop.com/pyHints/445
Create:
Last Update:

بنابراین بجای کلید class از () استفاده میشه.
و همونطور که قبلا هم گفتم هر چیزی که بعد از این بیاد ورودی‌هایی هست که اون کلاس قبول می‌کنه؛ من اینجا گفتم اگر توی dev نبودم فقط ۴ کاراکتر آخر شماره تلفن رو نشون بده ولی اگر روی dev بودم ۱۰ تاش رو نشون بده.

حالا فقط کافیه filter ایی که تعریف کردم رو به هرکدوم از handler هایی که لازم هست پاس بدم که توی خط 57 دارم اینکار رو برای file handler انجام میدم.
سوال : چطوری phone رو به logRecord اضافه کنیم ؟
خط ۷۵ رو ببینید؛ وقتی یک کلیدی داریم که بصورت دیفالت روی logger تعریف نشده؛ راه قشنگش اینه که اون رو توی extra برای logger های مورد نظر ارسال کنیم:
logger.critical("Call meeeeeeee", extra={"phone": "09121212122"})
خروجی میشه چیزی که توی تصویر می‌بینید.

BY Python Hints





Share with your friend now:
tgoop.com/pyHints/445

View MORE
Open in Telegram


Telegram News

Date: |

Private channels are only accessible to subscribers and don’t appear in public searches. To join a private channel, you need to receive a link from the owner (administrator). A private channel is an excellent solution for companies and teams. You can also use this type of channel to write down personal notes, reflections, etc. By the way, you can make your private channel public at any moment. There have been several contributions to the group with members posting voice notes of screaming, yelling, groaning, and wailing in different rhythms and pitches. Calling out the “degenerate” community or the crypto obsessives that engage in high-risk trading, Co-founder of NFT renting protocol Rentable World emiliano.eth shared this group on his Twitter. He wrote: “hey degen, are you stressed? Just let it out all out. Voice only tg channel for screaming”. With the sharp downturn in the crypto market, yelling has become a coping mechanism for many crypto traders. This screaming therapy became popular after the surge of Goblintown Ethereum NFTs at the end of May or early June. Here, holders made incoherent groaning sounds in late-night Twitter spaces. They also role-played as urine-loving Goblin creatures. Avoid compound hashtags that consist of several words. If you have a hashtag like #marketingnewsinusa, split it into smaller hashtags: “#marketing, #news, #usa. Administrators
from us


Telegram Python Hints
FROM American