1. 程式人生 > >python 日誌 logging

python 日誌 logging

count pat edi () def port pre delay cti

import os
import logging
from logging.handlers import RotatingFileHandler
import platform

platform_ = platform.system()
is_win = is_linux = is_mac = False

if platform_ == "Windows":
    is_win = True
elif platform_ == "Linux":
    is_linux = True
elif platform_ == "Mac":
    is_mac = True


def init_logging(log_file_path=None, file_name=‘out.log‘):
    path = log_file_path
    if not os.path.exists(path):
        os.makedirs(path)
    logging.basicConfig(
        handlers=[RotatingFileHandler(path + file_name,
                      # 設置 日子文件大小100M 超過自動換文件 maxBytes=100 * 1024 * 1024, backupCount=5, encoding=‘utf-8‘, delay=0), logging.StreamHandler()], level=logging.INFO, format=‘%(asctime)s.%(msecs)03d %(thread)d %(levelname)s %(module)s %(lineno)d - %(funcName)s : %(message)s‘, datefmt="%Y-%m-%d %H:%M:%S")

  

python 日誌 logging