"Stop Printing, Start Logging!" (Logging Tutorial For Python Developers)

Поделиться
HTML-код
  • Опубликовано: 28 июн 2024
  • Logging is far more powerful than printing in Python. It really gives you a lot of free information, so in this video I will teach you the basics of how you can get started with using the logging module in Python, so that you can create far more detailed logs!
    Logrecord Attributes:
    docs.python.org/3/library/log...
    ▶ Become job-ready with Python:
    www.indently.io
    ▶ Follow me on Instagram:
    / indentlyreels
    00:00 Intro
    00:24 import logging
    00:34 What is logging?
    00:46 Logging levels
    03:39 Log file
    04:20 Adding variables
    05:50 Creating detailed logs
    06:43 Formatting
    12:40 Conclusion

Комментарии • 45

  • @arhamsayyed9518
    @arhamsayyed9518 Год назад +48

    A tutorial no one asked for but everyone needed

  • @higiniofuentes2551
    @higiniofuentes2551 Год назад +13

    For the young developers: the creation of a log file is vital in production to quickly detect/follow any failure!

  • @behnamheydarian9569
    @behnamheydarian9569 10 месяцев назад +9

    It will be great if you add real-world examples in your videos.
    It helps to understand where these modules are used

  • @SuperVirus1978
    @SuperVirus1978 Год назад +5

    Thank you for this video.
    There is another reason why you should use the "old" method of string formatting instead of f-strings:
    The message string is only expanded/formatted if it is printed/logged - so it will save some procesing power, especially for debug messages which a rarely enabled.
    If you use a f-string it will be formatted before it is handed over to the logger - regardles if it is used or not.

  • @littlehuman4860
    @littlehuman4860 Год назад

    exactly the tutorial I needed, I heard about logging few days ago and was planning to check it out

  • @williamsusa5067
    @williamsusa5067 Год назад +30

    What is the fastest way to learn Python?

    • @MeiLinFjellstad-oe2cc
      @MeiLinFjellstad-oe2cc Год назад +7

      For me it was learning through books that have interactive content. That way you practice while you learn is easier to remember what you just learned. I learned with:
      "Programming Not Painfully Boring" for the basics of programming and "Smarter Way to Learn Python".

    • @gpt.answers
      @gpt.answers Год назад

      coding

  • @nicflatterie7772
    @nicflatterie7772 11 месяцев назад

    Well done, to the point, clear, will look for your other videos.

  • @Try95th
    @Try95th Год назад +1

    Huh. I've been writing my own logging functions. This might come in handy in the next project. Thanks!

  • @bozok1903
    @bozok1903 Год назад

    Tankyou for the video. It's another very informative and important subject. I have created a user snippet for logging and using it all the time.

  • @MrValVet
    @MrValVet Год назад +1

    I love your tutorials. Very well explained. Thanks!

  • @user-vb9mv9xb1x
    @user-vb9mv9xb1x Месяц назад

    exactly what I need right now, thanks!

  • @Diegos79
    @Diegos79 8 месяцев назад

    Excellent teaching. Thanks!

  • @higiniofuentes2551
    @higiniofuentes2551 Год назад

    Thank you for this very useful video!

  • @FranciscoAntonio-fh1eu
    @FranciscoAntonio-fh1eu Год назад

    Thank you very much bro !!!

  • @ShehlaGhaffar
    @ShehlaGhaffar 17 дней назад

    Thank you soooooooooo much, it worked all perfectly in the project at work, where we have build an AI chatbot for space sector training solutions.

  • @martin_460
    @martin_460 Год назад +1

    AFAIR a classic string formatting ala `log.error("Cant find file %s", filename)` is preferred, so tools and services like Sentry can properly group messages.

  • @kattamaran
    @kattamaran Год назад +5

    Nice start. Could use a better, real world example. Like combining it with a normal exception you run into and how to log that. Or maybe with a debug example where you try to follow a variable? Is that an example you would use it for in the real world? Im a beginner.. I usually struggle with youtube tutorials because they lack real world examples.

    • @WondrousHello
      @WondrousHello Год назад +3

      Yeah I was gonna say the same. Need to see this properly in action to understand why it’s useful. Seems just like print with extra steps at the moment.

  • @mariodemarco8973
    @mariodemarco8973 Год назад

    Great, already known, that logging lib is there, but this made it more clear. I just wonder if it possible to change config for the level during the code is excuted (e.g. use debug for some new code) while keeping warning for the rest. further, I figured out, that style="{" in the basicconfig enables better formatting like this {asctime:

  • @bygracethroughfaith3213
    @bygracethroughfaith3213 21 день назад

    Thank you 🥺🥰💕

  • @elpiloto100
    @elpiloto100 Год назад +1

    12:30 If you import hello_module before basicConfig, then the configurations passed to basicConfig won't be applied? Does that mean import logging and basicConfig needs be the first and second line in your program everytime?

  • @kiwiwelch3620
    @kiwiwelch3620 Год назад

    I need more of your videos

  • @HitBoxMaster
    @HitBoxMaster Год назад +1

    Are there even people running Python versions pre 3.6, where you don't have f-strings, or even worse, 2.7 where don't have the format() method? A more pertinent question still, why would even be concerned about this kind of backwards compatibility?
    Really cool video though. Would've been cool to see real case use though

  • @SolidBuildersInc
    @SolidBuildersInc 9 месяцев назад

    This was really an awesome share for debugging.
    I recently found pdb.
    import pdb
    Can't recall how to istantiate it but you may get something out of it.
    You can put break points and a host of things from the command line.
    The 2 of these tools together would be a great thing to have in the tool box for complex applications.
    I really like the logging of imported modules.
    Breadcrumb Vacuum Cleaner
    Kudos

  • @joelhatsch6618
    @joelhatsch6618 Год назад

    Problem I have is how to handle the log output. either it's too detailed or not enough, or I need different level of detail in different parts of the code etc... ist there a good viewer for the logfile that would maybe thread the output, allowing to collapse/expand the threaded messages. integration in visual studio would be a plus 😀

  • @elpiloto100
    @elpiloto100 Год назад +1

    Is it possible to raise an error automatically with the logging.error and logging.critical call?

  • @mahdimalekifard4038
    @mahdimalekifard4038 11 месяцев назад +1

    perfect content

  • @iamworstgamer
    @iamworstgamer Год назад

    which ide you are using

  • @josecintron85
    @josecintron85 8 месяцев назад

    can you point different log levels to different files?

  • @manolomonetha8238
    @manolomonetha8238 Год назад

    Is there an option for global configuration?

  • @sg8nj
    @sg8nj 11 месяцев назад

    Have doubt:
    1. logging.basicConfig can create fille hanlder? .
    2. Have created two logging object using logging.basicConfig
    Is it possible to copy log content from log 1 to log 2. While copy I don't want to copy the timestamp, thread details from log1, need to copy only the content.

  • @Anshegar
    @Anshegar Год назад

    I think this lib need then you are finish app, and you need ,ake some login temp files, but in dev process print(1) is a GOD XD

  • @LiamInviteMelonTeee
    @LiamInviteMelonTeee Год назад

    I wonder how many of us watch both your and Mcoding's videos

  • @RoysIdea
    @RoysIdea 4 месяца назад

    Nice video, but why would anyone use such an archaic datetime format in a log file? Just stick to the default

  • @yashbhatt2164
    @yashbhatt2164 Год назад

    Please Please Pretty Please keep making videos like this. The world needs it. YOU ARE A PERSONAL HERO. 🤗

  • @nicenaija9952
    @nicenaija9952 Год назад

    Which ide is this

    • @adityasinha7664
      @adityasinha7664 Год назад

      Vs Code

    • @Jugular1st
      @Jugular1st Год назад +1

      Indently says its PyCharm in the video.

    • @giovannirossi943
      @giovannirossi943 Год назад +1

      @@adityasinha7664 Nope, it's PyCharm. He's using the new UI (beta)

  • @VinceKully
    @VinceKully 3 месяца назад

    loguru > built-in logging