码迷,mamicode.com
首页 > 其他好文 > 详细

logging模块

时间:2020-09-16 12:28:25      阅读:36      评论:0      收藏:0      [点我收藏+]

标签:debug   pat   project   security   user   exist   mod   format   base   

"""
Django settings for swiper project.

Generated by ‘django-admin startproject‘ using Django 1.11.15.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 4b0su5=ji*52rdx*)i2md_!h@+kb!-++fksqtb^(=n#r)&jb2)

# SECURITY WARNING: don‘t run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = [*]


# Application definition

INSTALLED_APPS = [
    django.contrib.contenttypes,
    django.contrib.sessions,
    django.contrib.staticfiles,
    user,
    social,
    vip,
]

MIDDLEWARE = [
    django.middleware.security.SecurityMiddleware,
    django.contrib.sessions.middleware.SessionMiddleware,
    django.middleware.common.CommonMiddleware,
    # ‘django.middleware.csrf.CsrfViewMiddleware‘,
    django.middleware.clickjacking.XFrameOptionsMiddleware,
    common.middleware.AuthMiddleware,
    common.middleware.LogicErrorMiddleware,
]

ROOT_URLCONF = swiper.urls

TEMPLATES = [
    {
        BACKEND: django.template.backends.django.DjangoTemplates,
        DIRS: [],
        APP_DIRS: True,
        OPTIONS: {
            context_processors: [
                django.template.context_processors.debug,
                django.template.context_processors.request,
            ],
        },
    },
]

WSGI_APPLICATION = swiper.wsgi.application


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
    default: {
        ENGINE: django.db.backends.sqlite3,
        NAME: os.path.join(BASE_DIR, db.sqlite3),
    },
    db1: {
        ENGINE: django.db.backends.sqlite3,
        NAME: os.path.join(BASE_DIR, db1.sqlite3),
    },
    db2: {
        ENGINE: django.db.backends.sqlite3,
        NAME: os.path.join(BASE_DIR, db2.sqlite3),
    },
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        NAME: django.contrib.auth.password_validation.UserAttributeSimilarityValidator,
    },
    {
        NAME: django.contrib.auth.password_validation.MinimumLengthValidator,
    },
    {
        NAME: django.contrib.auth.password_validation.CommonPasswordValidator,
    },
    {
        NAME: django.contrib.auth.password_validation.NumericPasswordValidator,
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = zh-hans

TIME_ZONE = Asia/Shanghai

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = /static/

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/0",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            "PICKLE_VERSION": -1,
            "PASSWORD": ""
        }
    }
}

REDIS = {
    Master: {
        host: 127.0.0.1,
        port: 6379,
        db: 1,
    },
    Slave: {
        host: 127.0.0.1,
        port: 6379,
        db: 1,
    }
}

MEDIA_ROOT = media

LOGGING = {
    version: 1,
    disable_existing_loggers: True,

    # 格式配置
    formatters: {
        simple: {
            format: %(asctime)s %(module)s.%(funcName)s: %(message)s,
            datefmt: %Y-%m-%d %H:%M:%S,
        },
        verbose: {
            format: (%(asctime)s %(levelname)s [%(process)d-%(threadName)s] 
                       %(module)s.%(funcName)s line %(lineno)d: %(message)s),
            datefmt: %Y-%m-%d %H:%M:%S,
        }
    },

    # Handler 配置
    handlers: {
        console: {
            class: logging.StreamHandler,
            level: DEBUG if DEBUG else WARNING
        },
        info: {
            class: logging.handlers.TimedRotatingFileHandler,
            filename: f{BASE_DIR}/logs/info.log,  # 日志保存路径
            when: D,  # 每天切割日志
            backupCount: 30,  # 日志保留 30 天
            formatter: simple,
            level: INFO,
        },
        error: {
            class: logging.handlers.TimedRotatingFileHandler,
            filename: f{BASE_DIR}/logs/error.log,  # 日志保存路径
            when: W0,  # 每周一切割日志
            backupCount: 4,  # 日志保留 4 周
            formatter: verbose,
            level: WARNING,
        }
    },

    # Logger 配置
    loggers: {
        django: {
            handlers: [console],
        },
        inf: {
            handlers: [info],
            propagate: True,
            level: INFO,
        },
        err: {
            handlers: [error],
            propagate: True,
            level: WARNING,
        }
    }
}

 

logging模块

标签:debug   pat   project   security   user   exist   mod   format   base   

原文地址:https://www.cnblogs.com/xuqidong/p/13604942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!