Archipelago icon indicating copy to clipboard operation
Archipelago copied to clipboard

WebHost: Bug: console log is suppressed when any keys are missing from options.yaml

Open strotlog opened this issue 2 years ago • 1 comments

What happened?

  1. git clone the repo
  2. Optional: create virtualenv
  3. Copy host.yaml -> options.yaml
  4. Remove any line from your now customized options.yaml
  5. python WebHost.py

Bug: The log message that you are hosting on 0.0.0.0: is missing, along with other log messages.

This bug was introduced by commit 4a2a184 ("Core: remove game-specific arguments from Generate (#971)", 2 days ago).

What were the expected results?

Expected: Logging to console works

Software

Local generation

strotlog avatar Sep 01 '22 18:09 strotlog

Analysis

Per debugger, here's what's going on.

  1. LTTP world init new behavior in 4a2a184: calls Utils.get_options() as soon as LTTP world is imported
  2. Utils.get_options writes a scary log message using logging.info if the yaml file that Utils chose to read (in this case, options.yaml; host.yaml is ignored) is missing any key that's present in the fixed/const dict returned by Utils.get_default_options() (which is almost identical to host.yaml, incidentally). This log message never reaches the console.
  3. After all of its imports, WebHost.py then runs logging.basicConfig(..., level=logging.INFO)
  4. As part of logging.basicConfig, because a log message was already emitted, /usr/lib/python3.10/logging/__init__.py had to go ahead and initialize a log handler already at the time of the log message. Therefore, now when we intentionally request to configure the log, logging ignores the request since it has already been set up.

Solution: black-sliver has suggested:

  • initializing logging earlier in WebHost.py; and
  • calling logging.basicConfig(..., force=True); and
  • redirecting all log statements that may occur at init time to a new wrapper so that they can be handled appropriately.

strotlog avatar Sep 01 '22 18:09 strotlog

@black-sliver I suspect this is fixed now?

Berserker66 avatar Sep 15 '23 07:09 Berserker66