From 377097d5cdd30e5ef7e67ae9abb9d13c3391450f Mon Sep 17 00:00:00 2001 From: "Robin R. Smith-Gilbert" Date: Mon, 30 Jul 2018 13:34:36 -0700 Subject: [PATCH 1/2] Added millisecond output to request and response logging using a new helper function, LogWithTime. Removed extraneous parameters from LogResponse --- CHANGELOG.md | 4 ++++ docs/_data/docs/WebHelpers.yml | 15 +++++++++++---- src/WebAsyncWrapper.cls | 2 +- src/WebClient.cls | 4 ++-- src/WebHelpers.bas | 25 ++++++++++++++++++++----- 5 files changed, 38 insertions(+), 12 deletions(-) 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..09282c36 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 Message & " - " & Format(Now, "yyyy-mm-dd hh:nn:ss.") & Right(Format(Timer, "#0.000"), 3) + + If NewLine Then + Debug.Print vbNewLine + End If + End If +End Sub + '' ' Obfuscate any secure information before logging. ' From efd97c3d61e030c2e0b5b1a28a62c2873652c780 Mon Sep 17 00:00:00 2001 From: "Robin R. Smith-Gilbert" Date: Wed, 3 Oct 2018 14:06:36 -0700 Subject: [PATCH 2/2] Flipped the timestamp to the beginning of the log message for more consistent output. --- src/WebHelpers.bas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebHelpers.bas b/src/WebHelpers.bas index 09282c36..ba81c0f5 100644 --- a/src/WebHelpers.bas +++ b/src/WebHelpers.bas @@ -577,7 +577,7 @@ End Sub '' Public Sub LogWithTime(Message As String, Optional NewLine As Boolean = False) If EnableLogging Then - Debug.Print Message & " - " & Format(Now, "yyyy-mm-dd hh:nn:ss.") & Right(Format(Timer, "#0.000"), 3) + Debug.Print Format(Now, "yyyy-mm-dd hh:nn:ss.") & Right(Format(Timer, "#0.000"), 3) & " - " & Message If NewLine Then Debug.Print vbNewLine