Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable colour in console output #896

Merged

Conversation

josecelano
Copy link
Member

@josecelano josecelano commented Jun 14, 2024

Enable colour in console output.

We were using the logging crate for logging. We move to tracing but keeping the same format for logs. The only difference was the colour introduced by the tracing crate. This is just a patch to allow using color with tracing. We parse the logs to extract the running services for example from these lines:

2024-06-10T16:07:39.989540Z  INFO torrust_tracker::bootstrap::logging: logging initialized.
2024-06-10T16:07:39.990205Z  INFO UDP TRACKER: Starting on: udp://0.0.0.0:6868
2024-06-10T16:07:39.990215Z  INFO UDP TRACKER: Started on: udp://0.0.0.0:6868
2024-06-10T16:07:39.990244Z  INFO UDP TRACKER: Starting on: udp://0.0.0.0:6969
2024-06-10T16:07:39.990255Z  INFO UDP TRACKER: Started on: udp://0.0.0.0:6969
2024-06-10T16:07:39.990261Z  INFO torrust_tracker::bootstrap::jobs: TLS not enabled
2024-06-10T16:07:39.990303Z  INFO HTTP TRACKER: Starting on: http://0.0.0.0:7070
2024-06-10T16:07:39.990439Z  INFO HTTP TRACKER: Started on: http://0.0.0.0:7070
2024-06-10T16:07:39.990448Z  INFO torrust_tracker::bootstrap::jobs: TLS not enabled
2024-06-10T16:07:39.990563Z  INFO API: Starting on http://127.0.0.1:1212
2024-06-10T16:07:39.990565Z  INFO API: Started on http://127.0.0.1:1212
2024-06-10T16:07:39.990577Z  INFO HEALTH CHECK API: Starting on: http://127.0.0.1:1313
2024-06-10T16:07:39.990638Z  INFO HEALTH CHECK API: Started on: http://127.0.0.1:1313

We extract these running services:

{
  "udp_trackers": [
    "127.0.0.1:6969"
  ],
  "http_trackers": [
    "http://127.0.0.1:7070"
  ],
  "health_checks": [
    "http://127.0.0.1:1313/health_check"
  ]
}

We should refactor the output format to take advantage of the new tracing crate. tracing supports structured fields on spans and events, so it would be easier to parse those services.

It was disabled becuase parsing lgos to extract the services URLs was
not working due to hidden color chars.

This changes the parser to ignore color chars.
@josecelano josecelano added this to the v3.0.0 milestone Jun 14, 2024
@josecelano josecelano linked an issue Jun 14, 2024 that may be closed by this pull request
@josecelano josecelano self-assigned this Jun 14, 2024
@josecelano
Copy link
Member Author

Sample coloured output:

image

Copy link

codecov bot commented Jun 14, 2024

Codecov Report

Attention: Patch coverage is 86.20690% with 4 lines in your changes missing coverage. Please review.

Project coverage is 78.53%. Comparing base (4832235) to head (eb928bc).

Files Patch % Lines
src/bootstrap/logging.rs 0.00% 1 Missing ⚠️
src/console/ci/e2e/runner.rs 0.00% 1 Missing ⚠️
src/console/clients/checker/app.rs 0.00% 1 Missing ⚠️
src/console/clients/udp/app.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #896      +/-   ##
===========================================
+ Coverage    78.50%   78.53%   +0.03%     
===========================================
  Files          171      171              
  Lines         9443     9458      +15     
===========================================
+ Hits          7413     7428      +15     
  Misses        2030     2030              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@josecelano
Copy link
Member Author

Regarding using tracing capabilities, for example, the folowwing Rust logging line:

info!(target: "UDP TRACKER", "Started on: udp://{}", address);

Produces this output:

2024-06-14T16:20:54.690047Z  INFO UDP TRACKER: Started on: udp://0.0.0.0:6969

But we could use instead:

event!(target: "UDP TRACKER", Level::INFO, started_on_socket_address = format!("udp://{}", address.to_string()));

Which produces:

2024-06-14T16:20:54.690052Z  INFO UDP TRACKER: started_on_socket_address="udp://0.0.0.0:6969"

I guess the second one is easier to parse: started_on_socket_address="THE_URL".

image

And it scales much better, we can add more fields. We have to research how this fits with new login styles like JSON format.

cc @da2ce7

@josecelano
Copy link
Member Author

ACK eb928bc

@josecelano josecelano merged commit a6054f1 into torrust:develop Jun 14, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable colour in console output
1 participant