dotnet-libp2p icon indicating copy to clipboard operation
dotnet-libp2p copied to clipboard

Improve logging

Open flcl42 opened this issue 2 years ago • 4 comments

  • Try https://learn.microsoft.com/en-us/dotnet/core/extensions/high-performance-logging approach
  • Clean up logging
  • Add documentation about log usage and when to use specific log levels

flcl42 avatar Sep 11 '23 11:09 flcl42

I would like to propose the implementation of an EventId system for our logs, which will consist of six digits.

The first three digits will be related to a specific project:

  • 1XX: Core projects such as Libp2p, Libp2p.Core
  • 2XX: Protocols, for example:
    • 200: Ping
    • 201: Plaintext
    • and so forth

The last three digits will determine the log level and the log's ID:

  • 000..099: Trace
  • 100..199: Debug
  • 200..299: Information
  • 300..399: Warning
  • 400..499: Error
  • 500..599: Critical

For example, the complete EventId for the Ping protocol could be 200100.

This system will provide a clear and structured way to identify events in our logs, making it easier to track and troubleshoot issues.

Please feel free to share your thoughts and feedback on this proposal.

I will prepare a PR for the Ping protocol to make it more clear. @flcl42

chertby avatar Sep 29 '23 21:09 chertby

@chertby it's good to have some structure but it seems like complication for potential contributors, another rule to keep in mind. Let's start by having just incremental numbers for the messages which is already a lot.

flcl42 avatar Oct 11 '23 07:10 flcl42

@flcl42 I’ll prepare a simpler version today.

chertby avatar Oct 11 '23 15:10 chertby

I still suggest leaving different event IDs for different protocols. But then use a simple increment. Use the name of the function itself as an event hire.

It’s simpler than the previous option, but we keep good logging, which should help with debugging.

I updated PR

private const int EventId = 200_000;

[LoggerMessage(
    EventId = EventId + 1,
    EventName = nameof(ReadingPong),
    Message = "Reading pong",
    Level = LogLevel.Trace)]
internal static partial void ReadingPong(
    this ILogger logger);

[LoggerMessage(
    EventId = EventId + 2,
    EventName = nameof(VerifyingPong),
    Message = "Verifying pong",
    Level = LogLevel.Trace)]
internal static partial void VerifyingPong(
    this ILogger logger);

chertby avatar Oct 12 '23 21:10 chertby