zoukankan      html  css  js  c++  java
  • ATM-conf-settings

    import os

    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    BASE_DB = os.path.join(BASE_DIR, 'db')
    BASE_LOG = os.path.join(BASE_DIR, 'log')

    standard_format = '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]'
    '[%(levelname)s][%(message)s]' # 其中name为getlogger指定的名字

    simple_format = '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'

    id_simple_format = '[%(levelname)s][%(asctime)s] %(message)s'

    # 定义日志输出格式 结束

    # 如果不存在定义的日志目录就创建一个
    if not os.path.isdir(BASE_LOG):
    os.mkdir(BASE_LOG)

    # log文件的全路径
    logfile_path = os.path.join(BASE_LOG, 'log.log')

    # log配置字典
    LOGGING_DIC = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
    'standard': {
    'format': standard_format
    },
    'simple': {
    'format': simple_format
    },
    },
    'filters': {},
    'handlers': {
    # 打印到终端的日志
    'console': {
    'level': 'DEBUG',
    'class': 'logging.StreamHandler', # 打印到屏幕
    'formatter': 'simple'
    },
    # 打印到文件的日志,收集info及以上的日志
    'default': {
    'level': 'DEBUG',
    'class': 'logging.handlers.RotatingFileHandler', # 保存到文件
    'formatter': 'standard',
    'filename': logfile_path, # 日志文件
    'maxBytes': 1024 * 1024 * 5, # 日志大小 5M
    'backupCount': 5,
    'encoding': 'utf-8', # 日志文件的编码,再也不用担心中文log乱码了
    },
    },
    'loggers': {
    # logging.getLogger(__name__)拿到的logger配置
    '': {
    'handlers': ['default', 'console'], # 这里把上面定义的两个handler都加上,即log数据既写入文件又打印到屏幕
    'level': 'INFO',
    'propagate': True, # 向上(更高level的logger)传递
    },
    },
    }
  • 相关阅读:
    about springmvc intergation jquery with ajax &noajax version
    spring mvc book very good
    use spring config editor to configure xsi:schemaLocation
    install firefox9 on ubuntu lucid
    TCMalloc : ThreadCaching Malloc
    ubuntu amd64bit lts lucid lynx image download address
    一个词评价python 和rails
    virtualbox ubuntu下使用设置
    how to install chromium on ubuntu lucid
    Extjs4 MVC 示例
  • 原文地址:https://www.cnblogs.com/wangcheng9418/p/9221746.html
Copyright © 2011-2022 走看看