Commit 580c78c8 authored by Christophe Benz's avatar Christophe Benz

Add LOG_LEVEL config key

parent 54339067
# Example config file. Copy and customize this file to ".env". Don't commit ".env". # Example config file. Copy and customize this file to ".env". Don't commit ".env".
LOG_LEVEL="INFO"
# For production deployment, see http://flask.pocoo.org/docs/1.0/tutorial/deploy/#configure-the-secret-key # For production deployment, see http://flask.pocoo.org/docs/1.0/tutorial/deploy/#configure-the-secret-key
SECRET_KEY="dev" SECRET_KEY="dev"
......
import json import json
import logging
import os import os
from pathlib import Path from pathlib import Path
from urllib.parse import quote_plus from urllib.parse import quote_plus
...@@ -11,9 +12,10 @@ from cachetools.func import ttl_cache ...@@ -11,9 +12,10 @@ from cachetools.func import ttl_cache
import opendataschema import opendataschema
# Let this import after app initialisation
from . import config from . import config
log = logging.getLogger(__name__)
@ttl_cache(maxsize=50, ttl=5*60) @ttl_cache(maxsize=50, ttl=5*60)
def download_with_cache(url): def download_with_cache(url):
...@@ -28,6 +30,7 @@ def schema_from_url(url): ...@@ -28,6 +30,7 @@ def schema_from_url(url):
# And load schema catalogs which urls are found in config.json # And load schema catalogs which urls are found in config.json
schema_catalog_map = {} schema_catalog_map = {}
if config.HOMEPAGE_CONFIG: if config.HOMEPAGE_CONFIG:
log.info("Initializing homepage sections...")
for section in config.HOMEPAGE_CONFIG['sections']: for section in config.HOMEPAGE_CONFIG['sections']:
if isinstance(section['catalog'], str) and section['catalog'].startswith('http'): if isinstance(section['catalog'], str) and section['catalog'].startswith('http'):
code = section['code'] code = section['code']
......
import json import json
import logging import logging
import os import os
import sys
from pathlib import Path from pathlib import Path
import requests import requests
...@@ -11,6 +12,15 @@ log = logging.getLogger(__name__) ...@@ -11,6 +12,15 @@ log = logging.getLogger(__name__)
load_dotenv() load_dotenv()
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
numeric_log_level = getattr(logging, LOG_LEVEL.upper(), None)
if not isinstance(numeric_log_level, int):
log.error('Invalid log level: {}'.format(LOG_LEVEL))
logging.basicConfig(
format="%(levelname)s:%(name)s:%(message)s",
level=numeric_log_level,
stream=sys.stderr, # script outputs data
)
SECRET_KEY = os.environ.get("SECRET_KEY") or None SECRET_KEY = os.environ.get("SECRET_KEY") or None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment