Unverified Commit b7b62183 authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #2414 from jumpserver/dev

[Update] gunicorn的日志
parents 4d402617 5a1b8941
...@@ -69,13 +69,13 @@ class Signer(metaclass=Singleton): ...@@ -69,13 +69,13 @@ class Signer(metaclass=Singleton):
self.secret_key = secret_key self.secret_key = secret_key
def sign(self, value): def sign(self, value):
s = JSONWebSignatureSerializer(self.secret_key) s = JSONWebSignatureSerializer(self.secret_key, algorithm_name='HS256')
return s.dumps(value).decode() return s.dumps(value).decode()
def unsign(self, value): def unsign(self, value):
if value is None: if value is None:
return value return value
s = JSONWebSignatureSerializer(self.secret_key) s = JSONWebSignatureSerializer(self.secret_key, algorithm_name='HS256')
try: try:
return s.loads(value) return s.loads(value)
except BadSignature: except BadSignature:
......
...@@ -26,6 +26,7 @@ CONFIG = load_user_config() ...@@ -26,6 +26,7 @@ CONFIG = load_user_config()
LOG_DIR = os.path.join(PROJECT_DIR, 'logs') LOG_DIR = os.path.join(PROJECT_DIR, 'logs')
JUMPSERVER_LOG_FILE = os.path.join(LOG_DIR, 'jumpserver.log') JUMPSERVER_LOG_FILE = os.path.join(LOG_DIR, 'jumpserver.log')
ANSIBLE_LOG_FILE = os.path.join(LOG_DIR, 'ansible.log') ANSIBLE_LOG_FILE = os.path.join(LOG_DIR, 'ansible.log')
GUNICORN_LOG_FILE = os.path.join(LOG_DIR, 'gunicorn.log')
if not os.path.isdir(LOG_DIR): if not os.path.isdir(LOG_DIR):
os.makedirs(LOG_DIR) os.makedirs(LOG_DIR)
...@@ -213,10 +214,21 @@ LOGGING = { ...@@ -213,10 +214,21 @@ LOGGING = {
'ansible_logs': { 'ansible_logs': {
'encoding': 'utf8', 'encoding': 'utf8',
'level': 'DEBUG', 'level': 'DEBUG',
'class': 'logging.FileHandler', 'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'main', 'formatter': 'main',
'maxBytes': 1024*1024*100,
'backupCount': 7,
'filename': ANSIBLE_LOG_FILE, 'filename': ANSIBLE_LOG_FILE,
}, },
'gunicorn_logs': {
'encoding': 'utf8',
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'main',
'maxBytes': 1024*1024*100,
'backupCount': 2,
'filename': GUNICORN_LOG_FILE,
},
}, },
'loggers': { 'loggers': {
'django': { 'django': {
...@@ -254,6 +266,10 @@ LOGGING = { ...@@ -254,6 +266,10 @@ LOGGING = {
'handlers': ['console', 'file'], 'handlers': ['console', 'file'],
'level': "INFO", 'level': "INFO",
}, },
'gunicorn': {
'handlers': ['console', 'gunicorn_logs'],
'level': LOG_LEVEL,
},
# 'django.db': { # 'django.db': {
# 'handlers': ['console', 'file'], # 'handlers': ['console', 'file'],
# 'level': 'DEBUG' # 'level': 'DEBUG'
...@@ -428,7 +444,7 @@ CELERY_WORKER_LOG_FORMAT = '%(message)s' ...@@ -428,7 +444,7 @@ CELERY_WORKER_LOG_FORMAT = '%(message)s'
CELERY_TASK_EAGER_PROPAGATES = True CELERY_TASK_EAGER_PROPAGATES = True
CELERY_WORKER_REDIRECT_STDOUTS = True CELERY_WORKER_REDIRECT_STDOUTS = True
CELERY_WORKER_REDIRECT_STDOUTS_LEVEL = "INFO" CELERY_WORKER_REDIRECT_STDOUTS_LEVEL = "INFO"
# CELERY_WORKER_HIJACK_ROOT_LOGGER = False # CELERY_WORKER_HIJACK_ROOT_LOGGER = True
CELERY_WORKER_MAX_TASKS_PER_CHILD = 40 CELERY_WORKER_MAX_TASKS_PER_CHILD = 40
# Cache use redis # Cache use redis
......
...@@ -5,7 +5,7 @@ import logging ...@@ -5,7 +5,7 @@ import logging
from django.core.cache import cache from django.core.cache import cache
from celery import subtask from celery import subtask
from celery.signals import ( from celery.signals import (
worker_ready, worker_shutdown, after_setup_logger worker_ready, worker_shutdown, after_setup_logger, setup_logging
) )
from kombu.utils.encoding import safe_str from kombu.utils.encoding import safe_str
from django_celery_beat.models import PeriodicTask from django_celery_beat.models import PeriodicTask
...@@ -45,8 +45,8 @@ def after_app_shutdown_periodic_tasks(sender=None, **kwargs): ...@@ -45,8 +45,8 @@ def after_app_shutdown_periodic_tasks(sender=None, **kwargs):
def add_celery_logger_handler(sender=None, logger=None, loglevel=None, format=None, **kwargs): def add_celery_logger_handler(sender=None, logger=None, loglevel=None, format=None, **kwargs):
if not logger: if not logger:
return return
handler = CeleryTaskFileHandler() task_handler = CeleryTaskFileHandler()
handler.setLevel(loglevel) task_handler.setLevel(loglevel)
formatter = logging.Formatter(format) formatter = logging.Formatter(format)
handler.setFormatter(formatter) task_handler.setFormatter(formatter)
logger.addHandler(handler) logger.addHandler(task_handler)
...@@ -149,7 +149,6 @@ def start_gunicorn(): ...@@ -149,7 +149,6 @@ def start_gunicorn():
if DAEMON: if DAEMON:
cmd.extend([ cmd.extend([
'--access-logfile', log_file,
'--daemon', '--daemon',
]) ])
else: else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment