Home  >  Article  >  Backend Development  >  How to view records in python

How to view records in python

(*-*)浩
(*-*)浩Original
2019-06-28 13:53:152941browse

The logging module is a standard module built into Python. It is mainly used to output running logs. It can set the output log level, log saving path, log file rollback, etc.; compared with print, it has the following advantages:

How to view records in python

You can set different log levels to output only important information in the release version without having to display a lot of debugging information; (recommended learning: Python video tutorial )

print outputs all information to the standard output, seriously affecting developers to view other data from the standard output; logging allows the developer to decide where to output the information. And how to output;

The logging module uses

to configure the basic logging settings, and then output the log on the console,

import logging
logging.basicConfig(level = logging.INFO,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

logger.info("Start print log")
logger.debug("Do something")
logger.warning("Something maybe fail.")
logger.info("Finish")

Runtime, console output,

2016-10-09 19:11:19,434 - __main__ - INFO - Start print log
2016-10-09 19:11:19,434 - __main__ - WARNING - Something maybe fail.
2016-10-09 19:11:19,434 - __main__ - INFO - Finish

You can choose many message levels in logging, such as debug, info, warning, error and critical. By assigning different levels to the logger or handler, developers can only output error information to a specific log file, or only record debugging information during debugging.

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to view records in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn