Flagsmith / edge-proxy

The Flagsmith Edge Proxy Docker Image
3 stars 3 forks source link

feat: Customised logging #115

Closed khvn26 closed 5 months ago

khvn26 commented 5 months ago

Logging config now accepts the override key, under which Python-compatible logging settings can be provided. The overridden settings take precedence over logging settings like enable_access_log, etc. default handler that utilises the log_format setting can be used in the override. For example, to log everything a file, one can set up own file handler and assign it to the root logger:

        "override": {
            "handlers": {
                "file": {
                    "level": "INFO",
                    "class": "logging.FileHandler",
                    "filename": "foo.log",
                    "formatter": "json"
                }
            },
            "loggers": {
                "": {
                    "handlers": [
                        "file"
                    ],
                    "level": "INFO",
                    "propagate": true
                }
            }
        }

Or, log access logs to file in generic format while logging everything else to stdout in json:

        "override": {
            "handlers": {
                "file": {
                    "level": "INFO",
                    "class": "logging.FileHandler",
                    "filename": "foo.log",
                    "formatter": "generic"
                }
            },
            "loggers": {
                "": {
                    "handlers": [
                        "default"
                    ],
                    "level": "INFO"
                },
                "uvicorn.access": {
                    "handlers": [
                        "file"
                    ],
                    "level": "INFO",
                    "propagate": false
                }
            }
        }

Additionally, the color setting key is added to control whether uvicorn and structlog logs should be colorised.