lifecycle: fix startup logs not being full json

This commit is contained in:
Jens Langhammer 2020-09-20 20:31:02 +02:00
parent 438e4efd49
commit 50c75087b8
2 changed files with 52 additions and 4 deletions

View file

@ -1,16 +1,28 @@
#!/usr/bin/env python #!/usr/bin/env python
"""This file needs to be run from the root of the project to correctly """This file needs to be run from the root of the project to correctly
import passbook. This is done by the dockerfile.""" import passbook. This is done by the dockerfile."""
from json import dumps
from sys import stderr
from time import sleep from time import sleep
from psycopg2 import OperationalError, connect from psycopg2 import OperationalError, connect
from redis import Redis from redis import Redis
from redis.exceptions import RedisError from redis.exceptions import RedisError
from structlog import get_logger
from passbook.lib.config import CONFIG from passbook.lib.config import CONFIG
LOGGER = get_logger()
def j_print(event: str, log_level: str = "info", **kwargs):
"""Print event in the same format as structlog with JSON.
Used before structlog is configured."""
data = {
"event": event,
"level": log_level,
"logger": __name__,
}
data.update(**kwargs)
print(dumps(data), file=stderr)
while True: while True:
try: try:
@ -24,7 +36,7 @@ while True:
break break
except OperationalError: except OperationalError:
sleep(1) sleep(1)
LOGGER.warning("PostgreSQL Connection failed, retrying...") j_print("PostgreSQL Connection failed, retrying...")
while True: while True:
try: try:
@ -38,4 +50,4 @@ while True:
break break
except RedisError: except RedisError:
sleep(1) sleep(1)
LOGGER.warning("Redis Connection failed, retrying...") j_print("Redis Connection failed, retrying...")

View file

@ -0,0 +1,36 @@
# Generated by Django 3.1.1 on 2020-09-20 12:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
(
"passbook_providers_oauth2",
"0004_remove_oauth2provider_post_logout_redirect_uris",
),
]
operations = [
migrations.AlterField(
model_name="oauth2provider",
name="response_type",
field=models.TextField(
choices=[
("code", "code (Authorization Code Flow)"),
(
"code#adfs",
"code (ADFS Compatibility Mode, sends id_token as access_token)",
),
("id_token", "id_token (Implicit Flow)"),
("id_token token", "id_token token (Implicit Flow)"),
("code token", "code token (Hybrid Flow)"),
("code id_token", "code id_token (Hybrid Flow)"),
("code id_token token", "code id_token token (Hybrid Flow)"),
],
default="code",
help_text="Response Type required by the client.",
),
),
]