Skip to content

Conversation

slin1237
Copy link
Collaborator

@slin1237 slin1237 commented Apr 25, 2025

Motivation

This PR implements logging for the SGL Router using the tracing. The logging system provides structured logs with timestamps, context information, and configurable log levels.

  • Structured logging with multiple log levels (TRACE, DEBUG, INFO, WARN, ERROR)
  • Simultaneous logging to console and files
  • JSON output format option for log analysis tools
  • Minimal overhead implementation with non-blocking I/O
    Safe initialization that prevents crashes when initialized multiple times

Modifications

  • Uses tracing, tracing-subscriber, tracing-log, and tracing-appender crates
  • Updated documentation in README.md
  • Added new logging.rs

Performance Benchmark

To ensure the logging implementation has minimal overhead, extensive benchmarking was performed. The benchmark measured the overhead of logging operations with different configurations:

  • Created a benchmark that executes the same operation with and without logging enabled
  • Measured the time per operation for:
    • No logging
    • Console-only logging
    • File logging (daily rolling files)

Results

Without logging (total): 99ns for 1,000,000 ops
With console logging (total): 395.498µs for 100,000 ops
With file logging (total): 2.018893ms for 100,000 ops

Time per operation without logging: 0.00 ns
Time per operation with console logging: 3.95 ns
Time per operation with file logging: 20.19 ns
  • Console logging: Adds only ~4 nanoseconds per log operation
  • File logging: Adds ~20 nanoseconds per log operation
  • These overheads are negligible for most operations and will not impact the router's performance

Screenshot 2025-04-24 at 11 51 49 PM

Checklist

@slin1237
Copy link
Collaborator Author

slin1237 commented Apr 25, 2025

Screenshot 2025-04-25 at 2 16 25 AM
previous logging

@slin1237 slin1237 force-pushed the slin/router-logs branch 2 times, most recently from 9d57f8b to 58f32d8 Compare April 25, 2025 09:32
@slin1237
Copy link
Collaborator Author

havent added all flags to the entry point yet, most of them are hardcoded in the code at the moment
we can turn them on later if we have to, such as json logging etc

Copy link
Collaborator

@ByronHsu ByronHsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. Thanks!

@slin1237 slin1237 merged commit f036582 into main Apr 27, 2025
4 checks passed
@slin1237 slin1237 deleted the slin/router-logs branch April 27, 2025 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants