If the env or gunicorn has some error, there will not be any error in console or error log file when we set the subprocss stdout to devnull. So I set it to None it will inhert its parent process stdout. When gunicorn cause error, it will show error in console.tags/0.7.0-beta
| @@ -32,10 +32,10 @@ timeout = 30 | |||||
| graceful_timeout = 30 | graceful_timeout = 30 | ||||
| daemon = False | daemon = False | ||||
| captureoutput = True | |||||
| captureoutput = False | |||||
| # write gunicorn default log to stream, and using mindinsight logger write gunicorn log to file. | |||||
| accesslog = '-' | |||||
| # write gunicorn default log to devnull, and using mindinsight logger write gunicorn log to file. | |||||
| accesslog = os.devnull | |||||
| def on_starting(server): | def on_starting(server): | ||||
| @@ -199,14 +199,18 @@ class GunicornLogger(Logger): | |||||
| """Rewrite gunicorn default logger.""" | """Rewrite gunicorn default logger.""" | ||||
| def __init__(self, cfg): | def __init__(self, cfg): | ||||
| self.access_log = setup_logger('gunicorn', 'access') | |||||
| self.error_log = setup_logger('gunicorn', 'error') | |||||
| super(GunicornLogger, self).__init__(cfg) | |||||
| self.cfg = cfg | |||||
| self.access_log = setup_logger('gunicorn', 'access', formatter='%(message)s') | |||||
| self.error_log = setup_logger('gunicorn', 'error', formatter=self.error_fmt) | |||||
| access_log_path = _get_access_log_path() | access_log_path = _get_access_log_path() | ||||
| error_log_path = _get_error_log_path() | error_log_path = _get_error_log_path() | ||||
| os.chmod(access_log_path, stat.S_IREAD | stat.S_IWRITE) | os.chmod(access_log_path, stat.S_IREAD | stat.S_IWRITE) | ||||
| os.chmod(error_log_path, stat.S_IREAD | stat.S_IWRITE) | os.chmod(error_log_path, stat.S_IREAD | stat.S_IWRITE) | ||||
| def now(self): | |||||
| """return Log Format""" | |||||
| return time.strftime('[%Y-%m-%d-%H:%M:%S %z]') | |||||
| def _get_all_ip_addresses(host): | def _get_all_ip_addresses(host): | ||||
| """Get all the accessible IP address.""" | """Get all the accessible IP address.""" | ||||
| @@ -255,7 +259,7 @@ def start(): | |||||
| shell=False, | shell=False, | ||||
| # Change stdout to DEVNULL to prevent broken pipe error when creating new processes. | # Change stdout to DEVNULL to prevent broken pipe error when creating new processes. | ||||
| stdin=subprocess.DEVNULL, | stdin=subprocess.DEVNULL, | ||||
| stdout=subprocess.DEVNULL, | |||||
| stdout=None, | |||||
| stderr=subprocess.STDOUT | stderr=subprocess.STDOUT | ||||
| ) | ) | ||||
| @@ -51,7 +51,7 @@ def _calc_default_max_processes_cnt(): | |||||
| LOG_FORMAT = '[%(levelname)s] MI(%(process)d:%(thread)d,%(processName)s):%(asctime)s ' \ | LOG_FORMAT = '[%(levelname)s] MI(%(process)d:%(thread)d,%(processName)s):%(asctime)s ' \ | ||||
| '[%(filepath)s:%(lineno)d][%(sub_module)s] %(message)s' | '[%(filepath)s:%(lineno)d][%(sub_module)s] %(message)s' | ||||
| GUNICORN_ACCESS_FORMAT = "'%(h)s <%(r)s> %(s)s %(b)s <%(f)s> <%(a)s> %(D)s'" | |||||
| GUNICORN_ACCESS_FORMAT = "'%(t)s %(h)s <%(r)s> %(s)s %(b)s <%(f)s> <%(a)s> %(L)s '" | |||||
| LOG_LEVEL = logging.INFO | LOG_LEVEL = logging.INFO | ||||
| # rotating max bytes, default is 50M | # rotating max bytes, default is 50M | ||||
| @@ -189,7 +189,7 @@ def setup_logger(sub_module, log_name, **kwargs): | |||||
| if not formatter: | if not formatter: | ||||
| formatter = settings.LOG_FORMAT | formatter = settings.LOG_FORMAT | ||||
| if kwargs.get('console', True): | |||||
| if kwargs.get('console', False): | |||||
| console_handler = logging.StreamHandler(sys.stdout) | console_handler = logging.StreamHandler(sys.stdout) | ||||
| console_handler.formatter = MindInsightFormatter(sub_module, formatter) | console_handler.formatter = MindInsightFormatter(sub_module, formatter) | ||||
| logger.addHandler(console_handler) | logger.addHandler(console_handler) | ||||