Skip to content

Commit 7de08ac

Browse files
committed
Fix and improve logging output
1 parent cafd4a6 commit 7de08ac

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

tests/trinity/integration/test_trinity_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def test_txpool_deactivated(async_process_runner, command):
8787
assert await contains_all(async_process_runner.stderr, {
8888
"Started DB server process",
8989
"Started networking process",
90-
"The transaction pool is not yet available in light mode",
90+
"Transaction pool not available in light mode",
9191
})
9292

9393

trinity/events.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55

66
class ShutdownRequest(BaseEvent):
7-
pass
7+
8+
def __init__(self, reason: str="") -> None:
9+
self.reason = reason

trinity/extensibility/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def __init__(self, endpoint: Endpoint) -> None:
6464
self.args: Namespace = None
6565
self.trinity_config: TrinityConfig = None
6666

67-
def shutdown_host(self) -> None:
67+
def shutdown_host(self, reason: str) -> None:
6868
self.event_bus.broadcast(
69-
ShutdownRequest(),
69+
ShutdownRequest(reason),
7070
BroadcastConfig(filter_endpoint=MAIN_EVENTBUS_ENDPOINT)
7171
)
7272

trinity/main.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ def trinity_boot(args: Namespace,
262262
networking_process,
263263
plugin_manager,
264264
main_endpoint,
265-
event_bus
265+
event_bus,
266+
ev.reason
266267
)
267268
)
268269

@@ -279,7 +280,8 @@ def trinity_boot(args: Namespace,
279280
networking_process,
280281
plugin_manager,
281282
main_endpoint,
282-
event_bus
283+
event_bus,
284+
reason="CTRL+C / Keyboard Interrupt"
283285
)
284286

285287

@@ -289,7 +291,7 @@ def kill_trinity_gracefully(logger: logging.Logger,
289291
plugin_manager: PluginManager,
290292
main_endpoint: Endpoint,
291293
event_bus: EventBus,
292-
message: str="Trinity shudown complete\n") -> None:
294+
reason: str=None) -> None:
293295
# When a user hits Ctrl+C in the terminal, the SIGINT is sent to all processes in the
294296
# foreground *process group*, so both our networking and database processes will terminate
295297
# at the same time and not sequentially as we'd like. That shouldn't be a problem but if
@@ -300,7 +302,9 @@ def kill_trinity_gracefully(logger: logging.Logger,
300302
# Notice that we still need the kill_process_gracefully() calls here, for when the user
301303
# simply uses 'kill' to send a signal to the main process, but also because they will
302304
# perform a non-gracefull shutdown if the process takes too long to terminate.
303-
logger.info('Keyboard Interrupt: Stopping')
305+
306+
hint = f"({reason})" if reason else f""
307+
logger.info('Shutting down Trinity %s', hint)
304308
plugin_manager.shutdown_blocking()
305309
main_endpoint.stop()
306310
event_bus.stop()
@@ -312,9 +316,7 @@ def kill_trinity_gracefully(logger: logging.Logger,
312316
kill_process_gracefully(process, logger)
313317
logger.info('%s process (pid=%d) terminated', name, process.pid)
314318

315-
# This is required to be within the `kill_trinity_gracefully` so that
316-
# plugins can trigger a shutdown of the trinity process.
317-
ArgumentParser().exit(message=message)
319+
ArgumentParser().exit(message=f"Trinity shutdown complete {hint}\n")
318320

319321

320322
@setup_cprofiler('run_database_process')

trinity/plugins/builtin/ethstats/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ def ready(self) -> None:
8181
self.logger.error(
8282
'You must provide ethstats server url using the `--ethstats-server-url`'
8383
)
84-
self.context.shutdown_host()
84+
self.context.shutdown_host("Missing EthStats Server URL")
8585
return
8686

8787
if not args.ethstats_server_secret:
8888
self.logger.error(
8989
'You must provide ethstats server secret using `--ethstats-server-secret`'
9090
)
91-
self.context.shutdown_host()
91+
self.context.shutdown_host("Missing EthStats Server Secret")
9292
return
9393

9494
if (args.ethstats_server_url):

trinity/plugins/builtin/tx_pool/plugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def ready(self) -> None:
6262
unsupported = self.context.args.tx_pool and light_mode
6363

6464
if unsupported:
65-
self.logger.error('The transaction pool is not yet available in light mode')
66-
self.context.shutdown_host()
65+
unsupported_msg = "Transaction pool not available in light mode"
66+
self.logger.error(unsupported_msg)
67+
self.context.shutdown_host(unsupported_msg)
6768

6869
self.event_bus.subscribe(ResourceAvailableEvent, self.handle_event)
6970

0 commit comments

Comments
 (0)