diff --git a/CHANGELOG.md b/CHANGELOG.md index 86662bbe..b350db44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 4.1.1 +- Added millisecond output to request and response logging using a new helper function, LogWithTime +- Removed extraneous parameters from LogResponse + # 4.1.0 - Update `UrlEncode` behavior to target different encoding RFCs based on `UrlEncodingMode` diff --git a/docs/_data/docs/WebHelpers.yml b/docs/_data/docs/WebHelpers.yml index 84faf47e..39ce57d8 100644 --- a/docs/_data/docs/WebHelpers.yml +++ b/docs/_data/docs/WebHelpers.yml @@ -161,11 +161,18 @@ Methods: # LogResponse - name: LogResponse - code: "LogResponse(Client, Request, Response)" + code: "LogResponse(Response)" details: - Client: "`{WebClient}`" - Request: "`{WebRequest}`" Response: "`{WebResponse}`" + description: | + Log the given string along with the current time specified to the millisecond. Optionally log a newline immediately following. + + # LogWithTime + - name: LogWithTime + code: "LogWithTime(Message, [NewLine])" + details: + Message: "`{String}`" + NewLine: "`{Boolean}` _Optional_" description: | Log details of the response (Status, headers, content, etc.). @@ -575,4 +582,4 @@ Methods: # StringToAnsiBytes - name: StringToAnsiBytes code: "StringToAnsiBytes(Text) {String}" - internal: true \ No newline at end of file + internal: true diff --git a/src/WebAsyncWrapper.cls b/src/WebAsyncWrapper.cls index 1a89a577..1e62d57b 100644 --- a/src/WebAsyncWrapper.cls +++ b/src/WebAsyncWrapper.cls @@ -192,7 +192,7 @@ Private Sub web_RunCallback(web_Response As WebResponse) ' Next i ' End Function - WebHelpers.LogResponse Me.Client, Me.Request, web_Response + WebHelpers.LogResponse web_Response If Not Me.Client.Authenticator Is Nothing Then Me.Client.Authenticator.AfterExecute Me.Client, Me.Request, web_Response diff --git a/src/WebClient.cls b/src/WebClient.cls index fc1acfa7..2331577e 100644 --- a/src/WebClient.cls +++ b/src/WebClient.cls @@ -324,7 +324,7 @@ Public Function Execute(Request As WebRequest) As WebResponse #End If - WebHelpers.LogResponse Me, Request, web_Response + WebHelpers.LogResponse web_Response If Not Me.Authenticator Is Nothing Then Me.Authenticator.AfterExecute Me, Request, web_Response @@ -347,7 +347,7 @@ web_ErrorHandling: web_Response.StatusCode = WebStatusCode.RequestTimeout web_Response.StatusDescription = "Request Timeout: " & Err.Description - WebHelpers.LogResponse Me, Request, web_Response + WebHelpers.LogResponse web_Response Set Execute = web_Response Err.Clear Case Else diff --git a/src/WebHelpers.bas b/src/WebHelpers.bas index b1940a20..ba81c0f5 100644 --- a/src/WebHelpers.bas +++ b/src/WebHelpers.bas @@ -523,7 +523,7 @@ End Sub '' Public Sub LogRequest(Client As WebClient, Request As WebRequest) If EnableLogging Then - Debug.Print "--> Request - " & Format(Now, "Long Time") + LogWithTime "--> Request" Debug.Print MethodToName(Request.Method) & " " & Client.GetFullUrl(Request) Dim web_KeyValue As Dictionary @@ -547,15 +547,13 @@ End Sub ' Log details of the response (Status, headers, content, etc.). ' ' @method LogResponse -' @param {WebClient} Client -' @param {WebRequest} Request ' @param {WebResponse} Response '' -Public Sub LogResponse(Client As WebClient, Request As WebRequest, Response As WebResponse) +Public Sub LogResponse(Response As WebResponse) If EnableLogging Then Dim web_KeyValue As Dictionary - Debug.Print "<-- Response - " & Format(Now, "Long Time") + LogWithTime "<-- Response" Debug.Print Response.StatusCode & " " & Response.StatusDescription For Each web_KeyValue In Response.Headers @@ -570,6 +568,23 @@ Public Sub LogResponse(Client As WebClient, Request As WebRequest, Response As W End If End Sub +'' +' Log the given string along with the current time specified to the millisecond. Optionally log a newline immediately following. +' +' @method LogWithTime +' @param {String} Message +' @param {Boolean} NewLine +'' +Public Sub LogWithTime(Message As String, Optional NewLine As Boolean = False) + If EnableLogging Then + Debug.Print Format(Now, "yyyy-mm-dd hh:nn:ss.") & Right(Format(Timer, "#0.000"), 3) & " - " & Message + + If NewLine Then + Debug.Print vbNewLine + End If + End If +End Sub + '' ' Obfuscate any secure information before logging. '