test

本文详细介绍了Python日志模块的高级配置方法,包括不同级别的日志输出、日志格式定制以及日志文件的滚动策略。同时,还涵盖了使用uwsgi进行Django项目的部署流程,包括配置文件设置及服务启动命令。
# log to file
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
       'standard': {
            'format': '%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s'
        },
        # 简单的日志格式
        'simple': {
            'format': '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
        }
    },
    # 处理器
    'handlers': {
        # 默認 系統運行信息全部打印到 logging.log
        'default': {
            'level': 'INFO',                    # 要打印系统运行信息是设为'DEBUG'
            'filename': 'logging.log',          # log file name
            'class': 'logging.handlers.RotatingFileHandler',
            'maxBytes': 1024 * 1024 * 50,       # 日誌文件大小
            'backupCount': 5,
            'formatter': 'simple'
        },
        'error':{
            'level': 'ERROR',
            'filename': 'error.log',            # log file name
            'class': 'logging.FileHandler',     # FileHandler: 處理類 輸出到磁盤文件
            'formatter': 'standard'
        },
        'console':{
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'standard'             # 使用哪種 formatters 日誌格式
        },
        # 专门定义一个收集特定信息的日志(暂时没用)
        'collect': {
            'level': 'INFO',
            'class': 'logging.FileHandler',     # FileHandler: 處理類 輸出到磁盤文件
            'filename':  "collect.log",
        }
    },
    # 记录器
    'loggers': {
        'django': {
            'handlers': ['default','error'],
            'level': 'DEBUG',
            'propagate': False                   # propagate 向不向更高級別的 loggers 傳遞
        },
        'collect': {                             # (暂时没用)
            'handlers': ['collect','console'],
            'level': 'INFO',
            'propagate': False,
        }
    },
}
#cmrc is your user name, you replace it with your user name.
[Unit]
Description=uWSGI instance to serve cmrc
After=syslog.target

[Service]
ExecStart=/bin/bash -c 'cd /home/cmrc/cmrc; source venv/bin/activate; uwsgi --ini cmrc_uwsgi.ini'
User=cmrc
Group=cmrc
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
appdirs==1.4.3
attrs==19.1.0
cached-property==1.5.1
certifi==2019.3.9
chardet==3.0.4
defusedxml==0.5.0
Django==2.1.7
idna==2.8
isodate==0.6.0
lxml==4.3.3
psycopg2==2.7.7
psycopg2-binary==2.7.7
pytz==2018.9
requests==2.21.0
requests-toolbelt==0.9.1
six==1.12.0
spyne==2.12.16
urllib3==1.24.1
uWSGI==2.0.18
zeep==3.3.1

[uwsgi]

; project dir
chdir = /home/cmrc/cmrc/cmrc/
; sock file path
socket = 127.0.0.1:8000
wsgi-file = cmrc/wsgi.py
processes = 30
threads = 6
stats = 127.0.0.1:8001
; a master process will respawn your processes when they die.
master = true
enable-threads = true
; reload whenever this config file changes
; %p is the full path of the current config file
touch-reload = %p
pidfile = cmrc_uwsgi.pid
daemonize = cmrc_uwsgi.log
uid = cmrc
gid = cmrc

转载于:https://www.cnblogs.com/JanSN/p/11313074.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值