|
43 | 43 | # Root logger configuration |
44 | 44 | global logger |
45 | 45 |
|
| 46 | +# Set logging format and level (default is warning) |
| 47 | +# All the API logging is forwarded to the uWSGI server and gets written into the log file `log/uwsgi-entity-api.log` |
| 48 | +# Log rotation is handled via logrotate on the host system with a configuration file |
| 49 | +# Do NOT handle log file and rotation via the Python logging to avoid issues with multi-worker processes |
| 50 | +logging.basicConfig(format='[%(asctime)s] %(levelname)s in %(module)s: %(message)s', level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S') |
| 51 | + |
46 | 52 | # Use `getLogger()` instead of `getLogger(__name__)` to apply the config to the root logger |
47 | 53 | # will be inherited by the sub-module loggers |
48 | | -try: |
49 | | - logger = logging.getLogger() |
50 | | - logger.setLevel(logging.DEBUG) # logger.setLevel(logging.INFO) |
51 | | - |
52 | | - # All the API logging is gets written into the same log file |
53 | | - # The uWSGI logging for each deployment disables the request logging |
54 | | - # but still captures the 4xx and 5xx errors to the file `log/uwsgi-entity-api.log` |
55 | | - # Log rotation is handled via logrotate on the host system with a configuration file |
56 | | - # Do NOT handle log file and rotation via the Python logging to avoid issues with multi-worker processes |
57 | | - log_file_handler = logging.FileHandler('../log/entity-api-' + time.strftime("%m-%d-%Y-%H-%M-%S") + '.log') |
58 | | - log_file_handler.setFormatter(logging.Formatter('[%(asctime)s] %(levelname)s in %(module)s: %(message)s')) |
59 | | - logger.addHandler(log_file_handler) |
60 | | -except Exception as e: |
61 | | - print("Error setting up global log file.") |
62 | | - print(str(e)) |
63 | | - |
64 | | -try: |
65 | | - logger.info("logger initialized") |
66 | | -except Exception as e: |
67 | | - print("Error opening log file during startup") |
68 | | - print(str(e)) |
| 54 | +logger = logging.getLogger() |
69 | 55 |
|
70 | 56 | # Specify the absolute path of the instance folder and use the config file relative to the instance path |
71 | 57 | app = Flask(__name__, instance_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'instance'), instance_relative_config = True) |
|
0 commit comments