BSiLabs / HttpTracer

MIT License
172 stars 13 forks source link

[Spec] Allow Verbosity to be changed #34

Closed dylanberry closed 5 years ago

dylanberry commented 5 years ago

Summary

Writing all request and response data can be a heavy operation. We need a mechanism to control verbosity on the fly.

API

HttpMessageParts Flags

[Flags]
public enum HttpMessageParts
{
    Unknown = 0
    None = 1,

    RequestBody = 2,
    RequestHeaders = 4,
    RequestAll = RequestBody | RequestHeaders,

    ResponseBody = 8,
    ResponseHeaders = 16,

    ResponseAll = ResponseBody | ResponseHeaders,

    All = ResponseAll | RequestAll
}

HttpTracerHandler Public Property

public HttpMessageParts Verbosity { get; set; } = HttpMessageParts.RequestAll | HttpMessageParts.ResponseHeaders;

HttpTracerHandler Public Static Property

NOTE: we must validate this is not set to HttpMessageParts.Unknown

public static HttpMessageParts DefaultVerbosity { get; set; } = HttpMessageParts.Unknown;

Usage

The developer will need to ensure the HttpTracerHandler instance is available in order to change the verbosity on the fly.

using HttpTracer;
public async Task GetMyData()
{
    var tracer = new HttpTracerHandler();
    tracer.Verbosity = HttpMessageParts.RequestHeaders | HttpMessageParts.ResponseHeaders;
    var client = new HttpClient(tracer);
    var result = await client.GetAsync("http://myserviceurl.com");
}
DanielCauser commented 5 years ago

Love it!!

ChaseFlorell commented 5 years ago

What about the idea of having a Default = 0 position on the enumerator. Default would then be handled two ways.

If the user does nothing, it'll be "Information" (or maybe Warning...)

The user can also set the default via a static method/property.

HttpTracerHandler.DefaultLogLevel = LogLevel.Error

This way they can have a global log level for all instances, as well as custom log levels per instance where necessary.

dylanberry commented 5 years ago

@ChaseFlorell I like both those suggestions. Thanks for the thoughts and feedback!

aritchie commented 5 years ago

What about offering the ability to take all HttpStatusCodes or a filtered list?

As a secondary part, add the ability to say parts of the Http body parts I want?

[Flags]
public enum HttpBodyParts
{
    RequestBody = 1,
    RequestHeaders = 2,
    RequestAll = RequestBody | RequestHeaders,

    ResponseBody = 4,
    ResponseHeaders = 8,

    ResponseAll = ResponseBody | ResponseHeaders,

    All = ResponseAll | RequestAll
}
dylanberry commented 5 years ago

This is definitely a better approach. I'll revise the spec.

dylanberry commented 5 years ago

I have a PR open for discussion purposes. #37