Skip to content

Improve logs: add target, identify running service, identify request #600

Closed
@josecelano

Description

@josecelano

Relates to: #387

When you run the tracker with info log level you see something like:

Starting:

Loading default configuration file: `./share/default/config/tracker.development.sqlite3.toml` ...
2024-01-12T09:14:39.457741276+00:00 [torrust_tracker::bootstrap::logging][INFO] logging initialized.
2024-01-12T09:14:39.458258441+00:00 [UDP Tracker][INFO] Starting on: udp://0.0.0.0:6969
2024-01-12T09:14:39.458310899+00:00 [UDP Tracker][INFO] Started on: udp://0.0.0.0:6969
2024-01-12T09:14:39.458331488+00:00 [torrust_tracker::bootstrap::jobs][INFO] TLS not enabled
2024-01-12T09:14:39.458409276+00:00 [HTTP Tracker][INFO] Starting on: http://0.0.0.0:7070
2024-01-12T09:14:39.458425826+00:00 [HTTP Tracker][INFO] Started on: http://0.0.0.0:7070
2024-01-12T09:14:39.458431496+00:00 [torrust_tracker::bootstrap::jobs][INFO] TLS not enabled
2024-01-12T09:14:39.458516663+00:00 [API][INFO] Starting on http://127.0.0.1:1212
2024-01-12T09:14:39.458519593+00:00 [API][INFO] Started on http://127.0.0.1:1212
2024-01-12T09:14:39.458532263+00:00 [Health Check API][INFO] Starting on: http://127.0.0.1:1313
2024-01-12T09:14:39.458575981+00:00 [Health Check API][INFO] Started on: http://127.0.0.1:1313

Finishing:

2024-01-12T09:14:54.200599386+00:00 [torrust_tracker][INFO] Torrust shutting down..
2024-01-12T09:14:54.200603706+00:00 [torrust_tracker::servers::signals][INFO] Global shutdown signal processed
2024-01-12T09:14:54.200640756+00:00 [torrust_tracker::servers::signals][INFO] Global shutdown signal processed
2024-01-12T09:14:54.200625836+00:00 [torrust_tracker::servers::health_check_api::server][INFO] Stopping Torrust Health Check API server o http://127.0.0.1:1313 ...
2024-01-12T09:14:54.200647715+00:00 [torrust_tracker::servers::signals][INFO] Global shutdown signal processed
2024-01-12T09:14:54.200677215+00:00 [torrust_tracker::servers::signals][INFO] Shutting down UDP server on socket address: udp://0.0.0.0:6969
2024-01-12T09:14:54.200658765+00:00 [torrust_tracker::servers::signals][INFO] Shutting down tracker API server on socket address: 127.0.0.1:1212
2024-01-12T09:14:54.200662015+00:00 [torrust_tracker::bootstrap::jobs::torrent_cleanup][INFO] Stopping torrent cleanup job..
2024-01-12T09:14:54.200686095+00:00 [torrust_tracker::servers::signals][INFO] Sending graceful shutdown signal
!! shuting down in 90 seconds !!
2024-01-12T09:14:54.200703515+00:00 [Health Check API][INFO] Stopped server running on: http://127.0.0.1:1313
2024-01-12T09:14:54.200648515+00:00 [torrust_tracker::servers::signals][INFO] Shutting down HTTP server on socket address: 0.0.0.0:7070
2024-01-12T09:14:54.200717685+00:00 [torrust_tracker::servers::signals][INFO] Sending graceful shutdown signal
!! shuting down in 90 seconds !!
2024-01-12T09:14:54.200771174+00:00 [torrust_tracker][INFO] Torrust successfully shutdown.

I have started replacing the context with the module namespace with a service ID.

  • [torrust_tracker::bootstrap::logging]: this is what I call a namespaced context for the log.
  • [UDP Tracker], [HTTP Tracker], [Health Check API]: those are permanent service identifiers.

The main advantage is logs are not coupled with implementation details.

I've also added the URL when started services are listening on, for example:

2024-01-12T09:14:39.458310899+00:00 [UDP Tracker][INFO] Started on: udp://0.0.0.0:6969

This is also useful because allows easily identifying running services for developers or other services.

Some services like GitHub Codespaces use the log to auto-discover exposed ports and to automatically port forwarding.

There are still some logs that use the namespaced context like:

2024-01-12T09:14:39.458331488+00:00 [torrust_tracker::bootstrap::jobs][INFO] TLS not enabled
2024-01-12T09:14:39.458431496+00:00 [torrust_tracker::bootstrap::jobs][INFO] TLS not enabled
...
2024-01-12T09:14:54.200625836+00:00 [torrust_tracker::servers::health_check_api::server][INFO] Stopping Torrust Health Check API server o http://127.0.0.1:1313 ...
2024-01-12T09:14:54.200677215+00:00 [torrust_tracker::servers::signals][INFO] Shutting down UDP server on socket address: udp://0.0.0.0:6969
2024-01-12T09:14:54.200658765+00:00 [torrust_tracker::servers::signals][INFO] Shutting down tracker API server on socket address: 127.0.0.1:1212
...

It would be convenient to change also those records.

There is also another extra critical improvement. The tracker can run multiple HTTP trackers and multiple UDP trackers. It's very important to identify which one the log line refers to. In some lines, I've added the socket address which, I think, is the best identifier for the service. Since all services are exposed via a socket. For example:

2024-01-12T09:14:39.458258441+00:00 [UDP Tracker][INFO] Starting on: udp://0.0.0.0:6969

However, not all lines identify the service the logs belong to. For example:

2024-01-12T09:14:39.458331488+00:00 [torrust_tracker::bootstrap::jobs][INFO] TLS not enabled

In this case, we don't know which service has not enabled TLS: the API, one of the HTTP trackers?

We should add, for example, the bind_address somewhere to the log line.

Proposals

Proposal 1

It could be the target:

2024-01-12T09:14:39.458310899+00:00 [UDP Tracker::0.0.0.0:6969][INFO] Started on: udp://0.0.0.0:6969

Proposal 2

It could be in the main body like this:

2024-01-12T09:14:39.458310899+00:00 [UDP Tracker][INFO] 0.0.0.0:6969 - Started on: udp://0.0.0.0:6969

Conclusion

I think I would use the proposal 2. I think the target should be used for things at compilation time and the body for things at runtime. But it's only my first impression.

Maybe we could use an enum for the body to force a certain format.

This could not be a priority since I don't think many people will run multiple trackers at the same time. In fact, I do not know if that's even a useful feature. Why would someone want to run multiple trackers with the same configuration and different ports @WarmBeer?

Tasks

  • Replace all namespaced log lines with a target. At least for the info log level.
  • Identify the concrete running socket service (potentially by using the bound address).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions