Example of using the logging module in Python, pythonlogging
The examples in this article describe how to use the logging module and share them with you for your reference. The specific method is as follows:
Import logging import OS log = logging. getLogger () formatter = logging. formatter ('[% (asctime) s] [% (name) s] % (levelname) s: % (message) s') stream_handler = logging. streamHandler () file_handler = logging. fileHandler (OS. path. join ("c: \", "analysis. log ") file_handler.setFormatter (formatter) stream_handler.setFormatter (formatter) log. addHandler (file_handler) log. addHandler (stream_handler) log. setLevel (logging. DEBUG) log. warn ("a warning % s" % "c :\\")
The program running result is as follows:
[10:23:58, 905] [root] WARNING: a warning c :\
I hope this article will help you with Python programming.
What is the concept of a module in python? Can I use a simple example?
A module is a file, and the imported file is imported into the corresponding module. You can use the classes, functions, variables, and other information defined in the module. If there are many modules, you can use packages to manage them. You can put the files into a folder and add a _ init _. py file.
Where is the default log file stored in the logging module of python?
When configuring log file objects, you need to fill in the location of the log file. I put them all according to project requirements.
No research is performed by default.