日志记录操作

# -*- coding: utf-8 -*-
import logging
import configparser
from send_email import email_api


def get_name(): # 获取当前操作的用户名
    config = configparser.ConfigParser()
    config.read("../ui/login.ini")
    name = config.get("logininfo", "username")
    # print(name)
    return name


def log(HisunPN, name, value):
    LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" #日志格式
    logging.basicConfig(filename='../log/record.log', level=logging.DEBUG, format=LOG_FORMAT)
    person = get_name()
    info = "person:%s    HisunPN: %s    %s  changed: %s" % (person, HisunPN, name, value)
    email_api.sendhandle(info, person).sendEmail()  # 发送邮件
    logging.info(info)

日志可以根据级别改变

posted @ 2018-12-12 11:29  Corey0606  阅读(188)  评论(0编辑  收藏  举报