doseiai / dosei

Dosei is the open source successor to AWS Fargate and Cloud Run
Apache License 2.0
54 stars 0 forks source link

Structured logging using Tokio's tracing_subscriber #20

Closed rahulkp220 closed 10 months ago

rahulkp220 commented 10 months ago

More here https://tokio.rs/tokio/topics/tracing It produces nice logging like,

2023-12-22T10:33:19.676923Z  INFO doseid::server: 18: Successfully connected to Postgres
2023-12-22T10:33:19.679547Z  INFO doseid::server: 39: Dosei running on http://127.0.0.1:8844 (Press CTRL+C to quit
2023-12-22T10:33:26.801176Z  INFO doseid::server::cluster: 70: ClusterInfo { replicas: [Ping { id: "be6d810a-36b3-4637-ae06-d661dab6f701", node_type: Replica, address: "127.0.0.1:8846", version: "0.0.1" }] }

as compared to

[2023-12-22T10:05:44Z INFO  doseid::server] Successfully connected to Postgres
[2023-12-22T10:05:44Z INFO  doseid::server] Dosei running on http://127.0.0.1:8844 (Press CTRL+C to quit

Optionally, the json feature flag can also allow to flexibly allow json logging like,

{"timestamp":"2023-12-22T10:26:16.359502Z","level":"INFO","fields":{"message":"Successfully connected to Postgres"},"target":"doseid::server","line_number":18}
{"timestamp":"2023-12-22T10:26:16.360810Z","level":"INFO","fields":{"message":"Dosei running on http://127.0.0.1:8844 (Press CTRL+C to quit"},"target":"doseid::server","line_number":39}