Python Logging: How to Write Logs Like a Pro!

preview_player
Показать описание
Logging can make all the difference in commercial software products, and it's essential to have a proper understanding of how to use it effectively. In this video, I dive into the details of Python’s built-in logging package, along with tips on how to make your logs easier to manage.

🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund

🔖 Chapters:
0:00 Intro
1:29 Logging basics
3:12 Configuring logging
5:07 Integration with logging services
8:48 Big mistake with logging
10:42 Outro

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

I would have loved to see your approach to logging from multiple processes in the same files. For example logging from a FastAPI application that uses uvicorn or gunicorn with multiple workers. Perhaps in a future video. Looking forward to that :)

I really love watching your videos. They're full of useful information.

andreitimofte
Автор

You are doing great videos, but IMHO this was a bit too basic, would love to see an even more deep dive into this module. Like setting it up for a bigger project, best practices, etc. Anyway, thanks a lot and have a nice weekend! 🙂

tjanos
Автор

Fantastic as always, would love a deep dive on the structlog library for your next video! really takes logging to the next level

tomvonheill
Автор

As it is named deep-dive I was a bit hoping the focus of the logging levels and what are the daily praxis where to log, and how to handle the multiple levels in the code. This is something after years of developing software I still struggle with. Sometimes it feels like every second line is a log, and sometimes there are 3 log lines in the full project (hyperbolic). It never found a good regular way / a principle to follow ... :)
Whatever! :) Keep going, I learned a lot from you the last year I have now in my daily praxis. It helped me a lot :)

oyla
Автор

I’m a terrible coder, but only do it for personal projects, and I never thought about using logging to replace the print statements I use when developing, this would save me having to find all the random print statements all over my code 😊

almostanengineer
Автор

Logging throughout a module is way more complicated than you’ve shown though. Can you show how you set that up?

allo
Автор

Great content as always Arjan! I think it would be also a good idea to show ways of not overly littering your code with logger calls (ie. using decorators, as in one of your recent videos, or perhaps using other methods) and perhaps demonstrating a real-world example of crucial logging within an app. All the best!

MateuszModrzejewski
Автор

I feel as though you just glossed over some of the basics and added the SysLog as a bonus. What about getLogger(__name__) combined with propagation? What about different handlers at different levels? What about custom formatters? What about using decorators to do your logging for you? If nothing else, there are some ideas for a future show :)

skewty
Автор

You're videos are absolutely brilliant but what I really love is the code being available. It saves me a lot of time when I come back to one of your videos I've already watched a couple times.

DmoneySauce
Автор

Nice. I would have loved if you had shown what's best practice to actually log and at which places in the code loog statements are supposed to be.

iPrometheusQ
Автор

Would love to see more advanced logging concepts especially unified logging in a big library

akashdesarda
Автор

Thanks Arjan! Could you do a follow up on structured logging?

keithm
Автор

This was a lot more basic than I was expecting. Python's logging has a lot of pitfalls that I would have liked addressed.

AceofSpades
Автор

That was very informative. I was avoiding logging like a fire but it's not as difficult as it initially seems.

pawjast
Автор

Great video as always!
Interesting to see use of rotating logs as well as multiple package log implementation.
I know I ran into issues with those when I first started writing in python.

NANA-btws
Автор

*Thanks Arjan!* That is super useful 👍

CodingIsFun
Автор

I've used grafana + loki for very long time. Its very efficient with little to no resources. It can be setup in multiple ways and there is also a package for python called python-logging-loki. Loki has a really nice and powerful logql language with which you can make awesome grafana dashboards.

MedievalChips
Автор

I would agree with other commenters, it's nice to get a basic intro to logging, but I'd really like to know WHAT I should be logging.

In theory I could put a debug log for every line of code I write stating would should happen, but I imagine this is overkill. Or is it? I don't know where to draw the line, it would be good to get some examples of what kinds of things you log, and what level is appropriate for them.

But good video, and I'm looking forward to a part 2 😉

jamie
Автор

Again an excellent video ! I'm actually pointing all my new devs to some of your videos so that I'm sure they pick up good practices (even old ones like me). I didn't know papertrail, and I'm now starting using it. it's perfect, though I'm a bit worried about anybody being able to send logs to my account (no real auth)

TheRealPoiscaille
Автор

I love your videos about theory and architecture....once you have been coding for a while and you are no longer a begginer this kind knowledge feels really escential.

duftcola
welcome to shbcf.ru