mirror of
https://github.com/element-hq/synapse.git
synced 2025-12-05 01:10:13 +00:00
Redirect stdout/stderr to logs after initialization (#19131)
This regressed in https://github.com/element-hq/synapse/pull/19121. I moved things in https://github.com/element-hq/synapse/pull/19121 because I thought that it made sense to redirect anything printed to `stdout`/`stderr` to the logs as early as possible. But we actually want to log any immediately apparent problems during initialization to `stderr` in the terminal so that they are obvious and visible to the operator. Now, I've moved `redirect_stdio_to_logs()` back to where it was previously along with some proper comment context for why we have it there.
This commit is contained in:
1
changelog.d/19131.misc
Normal file
1
changelog.d/19131.misc
Normal file
@@ -0,0 +1 @@
|
||||
Refactor and align app entrypoints (avoid `exit(1)` in our composable functions).
|
||||
@@ -369,6 +369,7 @@ async def start(admin_command_server: AdminCmdServer, args: argparse.Namespace)
|
||||
def main() -> None:
|
||||
homeserver_config, args = load_config(sys.argv[1:])
|
||||
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
||||
# Initialize and setup the homeserver
|
||||
admin_command_server = create_homeserver(homeserver_config)
|
||||
setup(admin_command_server)
|
||||
|
||||
|
||||
@@ -450,16 +450,21 @@ def main() -> None:
|
||||
# Create a logging context as soon as possible so we can start associating
|
||||
# everything with this homeserver.
|
||||
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
||||
# redirect stdio to the logs, if configured.
|
||||
if not homeserver_config.logging.no_redirect_stdio:
|
||||
redirect_stdio_to_logs()
|
||||
|
||||
# Initialize and setup the homeserver
|
||||
hs = create_homeserver(homeserver_config)
|
||||
try:
|
||||
setup(hs)
|
||||
except Exception as e:
|
||||
handle_startup_exception(e)
|
||||
|
||||
# For problems immediately apparent during initialization, we want to log to
|
||||
# stderr in the terminal so that they are obvious and visible to the operator.
|
||||
#
|
||||
# Now that we're past the initialization stage, we can redirect anything printed
|
||||
# to stdio to the logs, if configured.
|
||||
if not homeserver_config.logging.no_redirect_stdio:
|
||||
redirect_stdio_to_logs()
|
||||
|
||||
# Register a callback to be invoked once the reactor is running
|
||||
register_start(hs, start, hs)
|
||||
|
||||
|
||||
@@ -479,16 +479,21 @@ def main() -> None:
|
||||
# Create a logging context as soon as possible so we can start associating
|
||||
# everything with this homeserver.
|
||||
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
||||
# redirect stdio to the logs, if configured.
|
||||
if not homeserver_config.logging.no_redirect_stdio:
|
||||
redirect_stdio_to_logs()
|
||||
|
||||
# Initialize and setup the homeserver
|
||||
hs = create_homeserver(homeserver_config)
|
||||
try:
|
||||
setup(hs)
|
||||
except Exception as e:
|
||||
handle_startup_exception(e)
|
||||
|
||||
# For problems immediately apparent during initialization, we want to log to
|
||||
# stderr in the terminal so that they are obvious and visible to the operator.
|
||||
#
|
||||
# Now that we're past the initialization stage, we can redirect anything printed
|
||||
# to stdio to the logs, if configured.
|
||||
if not homeserver_config.logging.no_redirect_stdio:
|
||||
redirect_stdio_to_logs()
|
||||
|
||||
# Register a callback to be invoked once the reactor is running
|
||||
register_start(hs, start, hs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user