并行记录到控制台和日志文件
duallog的Python项目详细描述
DualLog软件包
python包,允许同时记录控制台和日志文件。
如何安装DualLog?
您可以使用pip安装duallog,也可以从源安装。 下面是两种方法的说明。
通过PIP安装
在终端中,运行pip install duallog
。
从源安装
- 下载并解压缩此存储库。
- 打开终端并导航到存储库。
- 从存储库中执行
python setup.py install
。
如何使用DualLog?
使用duallog非常简单,如下面的最小示例脚本所示。
# Import the duallog package to set up simultaneous logging to screen and console.importduallog# Import the logging package to generate log messages.importlogging# Set up dual logging and tell duallog where to store the logfiles.duallog.setup('logtest')# Generate some log messages.logging.debug('Debug messages are only sent to the logfile.')logging.info('Info messages are not shown on the console, too.')logging.warning('Warnings appear both on the console and in the logfile.')logging.error('Errors get the same treatment.')logging.critical('And critical messages, of course.')
此程序的输出显示在本页顶部的屏幕截图中。