How to use the logging module in python - How to use the logging module in python

Time: 2022-10-07Source: Huajun Software TutorialAuthor: Ai Xiaomo

Friends, do you know how to use the logging module in python? Today I will explain how to use the logging module. If you are interested, come and take a look with me. I hope it can help you.

The first step: Open the python editor pycharm and import a logging module in the python file.


Step 2: Then create a new function main below, and print 10/0 in this function. Obviously this is an error, and there will be an error message when it is executed!


Step 3: Then use the try statement to call the main function below to detect the main function.


Step 4: If there is an error, execute the exception error class and print out the error information through the logging module, but the subsequent code will still continue to execute!


Step 5: Write print(“end”) at the end and observe whether it is executed!


Step 6: Click the run command at the top and select the file to run.


Step 7: In the console below, we can see the printed error and the result of the continued execution of the subsequent code.


The above is the entire content of how to use the logging module in python that the editor has brought to you. I hope it can help you.

Related articles更多>>

Popular recommendations