Logging Implementation In Python
Key Takeaways
The video demonstrates logging implementation in Python using the logging module, covering topics such as log levels, handlers, and formatters. It provides a comprehensive overview of logging best practices and techniques for effective logging in Python applications.
Full Transcript
hello all my name is krishnak and welcome to my youtube channel so guys today in this particular video we are going to discuss about logging mechanism in python whenever probably you are developing a web application you may be developing a data science project application how easily you can basically logs now why logging is important because understand guys you handle some of the errors with the help of exceptional handling and we have already seen in python how to do the exception handling you can refer my complete python playlist for that the main thing is that when you are actually handling the exception it is also better that you try to capture those logs what is the error that are coming and probably save it in some kind of text file which in turn saves that information in some kind of database and probably try to see in a visualized manner you know like how many errors are actually coming how many warnings are actually coming how many critical errors are there and based on that you know when the system is in process you know it always helps us to monitor that entire results so in this particular video we are going to see how we can perform a logging in a much more easier way and here what i'm going to do is that in order to use logging you have to use this library which is called as import logging now here i've just used import random i don't require this so this logging library actually helps you to write logs probably create a text file create different types of files and try to write all the logs inside this now here what i'm going to do is that i'm just going to run a simple basic code again there is no much logic over here but i really wanted to show you some kind of understanding like how you can create a file how you can basically write all the logs inside that file and all so follow all what we have to do is that we have to set up the basic config information this basic config information basically says that what kind of file name i'm probably trying to create you know then what is the file mode file mode basically means that whether it is an append mode to write mode you know or right bytes mode uh right plus append mode so this kind of file modes we can actually give and this is basically the format now this format represents a lot of information so they are information like first of all this ase time basically shows that the timing like what kind of time it is basically a printing inside this particular text file with respect to the logs the second name is second parameter over here you can see something called as level name now level name over here actually shows you that what kind of error it is probably it is a warning error it is a critical error it is a error uh error mode basically so inside this right inside the logging object that we have a logging library that we have you know we have something like warning function critical function and error function this information gets captured inside this level name before going ahead with respect to this particular video this video has been sponsored by an academy so an academy has come up with this interview preparation batch which is starting on 24th feb especially for intermediate level folks which will help you get ready for the upcoming placements this is being taken by ria bunsel who herself is a techie in flipkart and will be able to guide you how to crack such interviews we also have the pagar who's the icpc world finalist for 2020 and his work at app time linux apart from this guys they're also some of the advantages of taking the unacademy subscription first of all when you take up a subscription you get access to all the batches and courses that are running currently and also the ones that have happened in the past so it is not a particular batch or a course that you are buying but access to all the paid courses you can also learn from your favorite teachers and be a part of all the courses and batches that are taken by them dedicated doubt session will be available so that you can asked out in live session additionally there is a doubt support on discord educators and reaching assistant solved doubts you also have an option to interact with your teacher through comments and emojis also have lives quizzes and polls in the class so check out the educators and different batches that are going on and the free classes made available for you by the court chef and an academy so apart from this guys you'll also be able to use my code that is kn06 to get 10 off on any subscriptions so all the information regarding this will be given in the description of this particular video and finally we have our message message is all the message that we are actually trying to print inside that particular log message right so here uh i'm also going to use a date format this date format is going to get printed in this ase time okay now here i have written a simple logic where i've said that for i in range 0 comma 15 i'm saying that if i percentile 2 is double equal to 0 i am just saying that log logging dot warning i'm just displaying some warning sim warning message you know i probably want to log some of the warning message over here right and over here you can see that if you have i percentile 3 is equal to 0 then i'm saying that okay it is a critical message no such logic guys just to show you how that particular message is printed i'm just writing this simple if else condition and finally in the else i'm just saying that okay if with other numbers other than that i percentile 2 is equal to 0 i percentile 3 is equal to 0 take all the other values as errors okay now this is what i have actually done right now suppose i say that if i divided by zero suppose there may be a scenario that my i value may also be zero right or probably i can say that i'll try to do some kind of operation where i'll say i divide by zero and for this you know we do some kind of exceptional handling like division by error and whenever we do this what i can do is that i can also capture this inside my try catch block like this right so try uh this will be my operation inside this like this okay right suppose i say i is equal to i equals i divided by 0 and then i can also write my except block and probably you know inside this exit block i may write logging dot critical error i'll say error and here probably i will say division by zero error right so something like this i can definitely do this right definitely i can do this and based on that that kind of logging information i can put it i'll try to show you this example also uh so what i'm going to do is that i'm going to remove this and now i'm just going to execute this entire code let's see what will happen and how it will run whether we'll be able to create our text chris.txt file and probably will be able to put up all these particular messages so let's do it i'll go this i'll just click on run main and after this i have my chris.text now here you can see uh 15 times because i'm iterating through 15 times right in my main.py so here you can see i for i in range 0 comma 15 and you know for this it is displaying log warning message whenever this condition gets satisfied it is displaying log warning then it is displaying log critical and then it it is probably displaying log error message this is very much important guys because whenever you are working on a very important project probably you really have to write this kind of logging mechanisms you know this is the first main thing so if i go and see in my cryst text you can see all the messages over here right lock critical error warnings everything is basically shown over here now what i'm going to do over here instead of writing like this probably i'll say that okay what i can say is that suppose i initialize i is equal to 10 right and probably i'll say i'll try to try create a try catch block if i say i is equal to i divided by 0 just to show you that division my error problem and here i'm just going to write my accept block and here i will probably handle this particular exception by saying that log logging dot error and this will basically have my essays message saying that division by zero right division by zero issue or error right i'll just write it out like this now this looks also pretty much fine uh and let me just run this uh and let's see how it will run so here you can see that it has successfully run if i go and see my text now here you can see division by zero error it is automatically logged over here with all these time parameters now see this guys we we selected this as our axi timestamp then this was our level name level name was either error warning or critical and this is basically the message that i'm trying to print isn't it amazing right because whenever you are developing a bigger application some of the other issues may come at various places and we should always be ready to handle that by using try catch block but when we are trying to handle that exception we should also be printing our logs in some text file probably putting inside a database and not right so this was a small idea about logging mechanism and python now what i'm going to do in my upcoming videos is that i'll take up entire logs of this probably use a database print put all these logs in transformation inside that database then pull all those information try to create a dashboard where you'll be able to see that how many critical messages have come how many error messages have come or how many warning messages have come in a visualized format and probably send that particular uh report to your stake manager stakeholders and all or your managers will be very much interested to see this kind of images and all so i hope you like this particular video in the next video i'll try to do that please do subscribe the channel if you're not a subscriber i'll see you all in the next video have a great day thank you and bye
Original Description
Join this structured, industry relevant and guided program to Crack those upcoming Interviews. Check the Batch Trailer and Course Plan by clicking on the link.
ELITE: Master Advanced Programming Topics and Become an Expert:
https://unacademy.com/batch/elite-master-advanced-programming-topics-and-become-an-expert/PHPO27EQ
Access all the free live classes in the current week here: http://unacademy.cc/daily_learning
Use Code KN06 to get 10% of on subscription
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I've been using Kite for a few months and I love it! https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=krishnaik&utm_content=description-only
All Playlist In My channel
Interview Playlist: https://www.youtube.com/playlist?list=PLZoTAELRMXVM0zN0cgJrfT6TK2ypCpQdY
Complete DL Playlist: https://www.youtube.com/watch?v=9jA0KjS7V_c&list=PLZoTAELRMXVPGU70ZGsckrMdr0FteeRUi
Julia Playlist: https://www.youtube.com/watch?v=Bxp1YFA6M4s&list=PLZoTAELRMXVPJwtjTo2Y6LkuuYK0FT4Q-
Complete ML Playlist :https://www.youtube.com/playlist?list=PLZoTAELRMXVPBTrWtJkn3wWQxZkmTXGwe
Complete NLP Playlist:https://www.youtube.com/playlist?list=PLZoTAELRMXVMdJ5sqbCK2LiM0HhQVWNzm
Docker End To End Implementation: https://www.youtube.com/playlist?list=PLZoTAELRMXVNKtpy0U_Mx9N26w8n0hIbs
Live stream Playlist: https://www.youtube.com/playlist?list=PLZoTAELRMXVNxYFq_9MuiUdn2YnlFqmMK
Machine Learning Pipelines: https://www.youtube.com/playlist?list=PLZoTAELRMXVNKtpy0U_Mx9N26w8n0hIbs
Pytorch Playlist: https://www.youtube.com/playlist?list=PLZoTAELRMXVNxYFq_9MuiUdn2YnlFqmMK
Feature Engineering :https://www.youtube.com/playlist?list=PLZoTAELRMXVPwYGE2PXD3x0bfKnR0cJjN
Live Projects :https://www.youtube.com/playlist?list=PLZoTAELRMXVOFnfSwkB_uyr4FT-327noK
Kaggle competition :https://www.youtube.
Playlist
Uploads from Krish Naik · Krish Naik · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Natural Language Processing|Stemming
Krish Naik
Natural Language Processing|BagofWords
Krish Naik
Gaussian distribution or Normal Distribution in statisctics
Krish Naik
Natural Language Processing|TF-IDF for Machine Learning| Text Prerocessing
Krish Naik
Log Normal Distribution in Statistics
Krish Naik
Covariance in Statistics
Krish Naik
Confusion matrix, Precision, Recall| Data Science Interview questions
Krish Naik
Tutorial 44-Balanced vs Imbalanced Dataset and how to handle Imbalanced Dataset
Krish Naik
Implementing a Spam classifier in python| Natural Language Processing
Krish Naik
Tutorial 11-Exploratory Data Analysis(EDA) of Titanic dataset
Krish Naik
Face Recognition using open CV and VGG 16 Transfer Learning
Krish Naik
Pedestrian Detection using OpenCV from Videos
Krish Naik
Face and Eye Detection from Videos using HAAR Cascade Classifier
Krish Naik
Reading, Writing and Displaying images with Opencv| OpenCV Tutorial
Krish Naik
OpenCV Installation | OpenCV tutorial
Krish Naik
Face and Eye Detection from Images using HAAR Cascade Classifier
Krish Naik
Car Detection using HAAR Cascade and Opencv from Videos.
Krish Naik
Using OpenFace for Face recognition in Keras
Krish Naik
OpenPose Tutorial with Tensorflow
Krish Naik
Multiple Linear Regression using python and sklearn
Krish Naik
Dimensional Reduction| Principal Component Analysis
Krish Naik
Movie Recommender System using Python
Krish Naik
TPR,FPR,FNR,TNR, Confusion Matrix
Krish Naik
Precision, Recall and F1-Score
Krish Naik
Artificial Neural Network for Customer's Exit Prediction from Bank
Krish Naik
GridSearchCV- Select the best hyperparameter for any Classification Model
Krish Naik
RandomizedSearchCV- Select the best hyperparameter for any Classification Model
Krish Naik
K Nearest Neighbor classification with Intuition and practical solution
Krish Naik
K Means Clustering Intuition
Krish Naik
Create custom Alexa Skill- Lambda function- Part2
Krish Naik
Hierarchical Clustering intuition
Krish Naik
Implement Transfer Learning with a generic Code Template
Krish Naik
Gender Classifier and Age Estimator using Resnet Convolution Neural Network
Krish Naik
Unlock Your Application With Your Face using OpenCV
Krish Naik
Draw rectangle from webcam and sketch process it on a live feed
Krish Naik
Complete Life Cycle of a Data Science Project
Krish Naik
How we can apply Machine Learning in Finance
Krish Naik
Deep Learning in Medical Science
Krish Naik
How to switch your career to Data Science.
Krish Naik
Linear Regression Mathematical Intuition
Krish Naik
Handle Categorical features using Python
Krish Naik
Machine Learning Algorithm- Which one to choose for your Problem?
Krish Naik
DBSCAN Clustering Easily Explained with Implementation
Krish Naik
Curse of Dimensionality Easily explained| Machine Learning
Krish Naik
Feature Selection Techniques Easily Explained | Machine Learning
Krish Naik
Tutorial 29-R square and Adjusted R square Clearly Explained| Machine Learning
Krish Naik
Cross Validation using sklearn and python | Machine Learning
Krish Naik
Handling Missing Data Easily Explained| Machine Learning
Krish Naik
Deploy Machine Learning Model using Flask
Krish Naik
Deployment of Deep Learning Model using Flask
Krish Naik
How to Visualize Multiple Linear Regression in python
Krish Naik
K Nearest Neighbour Easily Explained with Implementation
Krish Naik
Predicting Heart Disease using Machine Learning
Krish Naik
Predicting Lungs Disease using Deep Learning
Krish Naik
Stock Sentiment Analysis using News Headlines
Krish Naik
Random Forest(Bootstrap Aggregation) Easily Explained
Krish Naik
Voting Classifier(Hard Voting and Soft Voting Classifier)
Krish Naik
Credit Card Fraud Detection using Machine Learning from Kaggle
Krish Naik
Hyperparameter Optimization for Xgboost
Krish Naik
Tutorial 45-Handling imbalanced Dataset using python- Part 1
Krish Naik
Related Reads
📰
📰
📰
📰
Terraform 1.16 actions: the pre-destroy backup with a blind spot
Medium · DevOps
How to Integrate SAST and Dependency Scanning into Bitbucket Pipelines
Medium · DevOps
Debian 12 Entered LTS: Should You Upgrade Your Production VPS to Debian 13?
Medium · DevOps
Why Restrict PATH in Linux
Medium · DevOps
🎓
Tutor Explanation
DeepCamp AI