# Copyright 2022 99cloud
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


bind = "{{ api_interface_address }}:{{ skyline_apiserver_port }}"
workers = {{ skyline_gunicorn_workers }}
worker_class = "uvicorn.workers.UvicornWorker"
timeout = {{ skyline_gunicorn_timeout }}
keepalive = {{ skyline_gunicorn_keepalive }}
reuse_port = True
proc_name = "{{ project_name }}"

logconfig_dict = {
    "version": 1,
    "disable_existing_loggers": False,
    "root": {"level": "{{ skyline_gunicorn_debug_level }}", "handlers": ["console"]},
    "loggers": {
        "gunicorn.error": {
            "level": "{{ skyline_gunicorn_debug_level }}",
            "handlers": ["error_file"],
            "propagate": 0,
            "qualname": "gunicorn_error",
        },
        "gunicorn.access": {
            "level": "{{ skyline_gunicorn_debug_level }}",
            "handlers": ["access_file"],
            "propagate": 0,
            "qualname": "access",
        },
    },
    "handlers": {
        "error_file": {
            "class": "logging.handlers.RotatingFileHandler",
            "formatter": "generic",
            "filename": "{{ log_dir }}/skyline-error.log",
        },
        "access_file": {
            "class": "logging.handlers.RotatingFileHandler",
            "formatter": "generic",
            "filename": "{{ log_dir }}/skyline-access.log",
        },
        "console": {
            "class": "logging.StreamHandler",
            "level": "{{ skyline_gunicorn_debug_level }}",
            "formatter": "generic",
        },
    },
    "formatters": {
        "generic": {
            "format": "%(asctime)s.%(msecs)03d %(process)d %(levelname)s [-] %(message)s",
            "datefmt": "[%Y-%m-%d %H:%M:%S %z]",
            "class": "logging.Formatter",
        }
    },
}
