Tôi dường như đang gặp một số sự cố khi cố gắng triển khai đăng nhập vào dự án python của mình.Tập tin cấu hình ghi nhật ký Python
Tôi chỉ đơn giản là cố gắng bắt chước các cấu hình sau:
Python Logging to Multiple Destinations
Tuy nhiên, thay vì làm bên trong mã này, tôi muốn có nó trong một tập tin cấu hình.
Dưới đây là tập tin cấu hình của tôi:
[loggers]
keys=root
[logger_root]
handlers=screen,file
[formatters]
keys=simple,complex
[formatter_simple]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
[formatter_complex]
format=%(asctime)s - %(name)s - %(levelname)s - %(module)s : %(lineno)d - %(message)s
[handlers]
keys=file,screen
[handler_file]
class=handlers.TimedRotatingFileHandler
interval=midnight
backupCount=5
formatter=complex
level=DEBUG
args=('logs/testSuite.log',)
[handler_screen]
class=StreamHandler
formatter=simple
level=INFO
args=(sys.stdout,)
Vấn đề là đầu ra màn hình của tôi trông giống như:
2010-12-14 11: 39: 04.066 - gốc - CẢNH BÁO - 3
2010-12 -14 11: 39: 04,066 - root - ERROR - 4
2010-12-14 11: 39: 04,066 - root - CRITICAL - 5
Tệp của tôi là đầu ra, nhưng trông giống như trên (mặc dù với thêm thông tin). Tuy nhiên, mức gỡ rối và thông tin không được xuất ra.
Tôi đang trên Python 2,7
Dưới đây là ví dụ đơn giản của tôi cho thấy sự thất bại:
import os
import sys
import logging
import logging.config
sys.path.append(os.path.realpath("shared/"))
sys.path.append(os.path.realpath("tests/"))
class Main(object):
@staticmethod
def main():
logging.config.fileConfig("logging.conf")
logging.debug("1")
logging.info("2")
logging.warn("3")
logging.error("4")
logging.critical("5")
if __name__ == "__main__":
Main.main()