forked from Github-Mirrors/canaille
Logging is configurable
This commit is contained in:
parent
7e5dccd7eb
commit
033639a955
4 changed files with 53 additions and 0 deletions
|
@ -18,6 +18,7 @@ import canaille.well_known
|
|||
from flask import Flask, g, request, session
|
||||
from flask_babel import Babel
|
||||
from flask_themer import Themer, render_template, FileSystemThemeLoader
|
||||
from logging.config import dictConfig
|
||||
|
||||
from .flaskutils import current_user
|
||||
from .ldaputils import LDAPObject
|
||||
|
@ -90,11 +91,42 @@ def teardown_ldap_connection(app):
|
|||
g.ldap.unbind_s()
|
||||
|
||||
|
||||
def setup_logging(app):
|
||||
log_level = app.config.get("LOGGING", {}).get("LEVEL", "WARNING")
|
||||
if not app.config.get("LOGGING", {}).get("PATH"):
|
||||
handler = {
|
||||
"class": "logging.StreamHandler",
|
||||
"stream": "ext://flask.logging.wsgi_errors_stream",
|
||||
"formatter": "default",
|
||||
}
|
||||
else:
|
||||
handler = {
|
||||
"class": "logging.handlers.WatchedFileHandler",
|
||||
"filename": app.config["LOGGING"]["PATH"],
|
||||
"formatter": "default",
|
||||
}
|
||||
|
||||
dictConfig(
|
||||
{
|
||||
"version": 1,
|
||||
"formatters": {
|
||||
"default": {
|
||||
"format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s",
|
||||
}
|
||||
},
|
||||
"handlers": {"wsgi": handler},
|
||||
"root": {"level": log_level, "handlers": ["wsgi"]},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def setup_app(app):
|
||||
if SENTRY and app.config.get("SENTRY_DSN"):
|
||||
sentry_sdk.init(dsn=app.config["SENTRY_DSN"], integrations=[FlaskIntegration()])
|
||||
|
||||
try:
|
||||
setup_logging(app)
|
||||
|
||||
LDAPObject.root_dn = app.config["LDAP"]["ROOT_DN"]
|
||||
user_base = app.config["LDAP"]["USER_BASE"]
|
||||
if user_base.endswith(app.config["LDAP"]["ROOT_DN"]):
|
||||
|
|
|
@ -44,6 +44,15 @@ OIDC_METADATA_FILE = "canaille/conf/openid-configuration.json"
|
|||
# account. The default value is true.
|
||||
# SELF_DELETION = true
|
||||
|
||||
[LOGGING]
|
||||
# LEVEL can be one value among:
|
||||
# DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
# LEVEL = "WARNING"
|
||||
|
||||
# The path of the log file. If not set (the default) logs are
|
||||
# written in the standard error output.
|
||||
# PATH = ""
|
||||
|
||||
[LDAP]
|
||||
URI = "ldap://ldap"
|
||||
ROOT_DN = "dc=mydomain,dc=tld"
|
||||
|
|
|
@ -44,6 +44,17 @@ OIDC_METADATA_FILE = "conf/openid-configuration.json"
|
|||
# account. The default value is true.
|
||||
# SELF_DELETION = true
|
||||
|
||||
[LOGGING]
|
||||
# LEVEL can be one value among:
|
||||
# DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
# Defaults to WARNING
|
||||
# LEVEL = "WARNING"
|
||||
LEVEL = "DEBUG"
|
||||
|
||||
# The path of the log file. If not set (the default) logs are
|
||||
# written in the standard error output.
|
||||
# PATH = ""
|
||||
|
||||
[LDAP]
|
||||
URI = "ldap://127.0.0.1:5389"
|
||||
ROOT_DN = "dc=mydomain,dc=tld"
|
||||
|
|
|
@ -128,6 +128,7 @@ def configuration(slapd_server, smtpd, keypair_path):
|
|||
"SECRET_KEY": gen_salt(24),
|
||||
"OAUTH2_METADATA_FILE": "canaille/conf/oauth-authorization-server.sample.json",
|
||||
"OIDC_METADATA_FILE": "canaille/conf/openid-configuration.sample.json",
|
||||
"LOGGING": {},
|
||||
"LDAP": {
|
||||
"ROOT_DN": slapd_server.suffix,
|
||||
"URI": slapd_server.ldap_uri,
|
||||
|
|
Loading…
Reference in a new issue