Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Logging #357

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
15 changes: 11 additions & 4 deletions docs/_data/docs/WebHelpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.).

Expand Down Expand Up @@ -575,4 +582,4 @@ Methods:
# StringToAnsiBytes
- name: StringToAnsiBytes
code: "StringToAnsiBytes(Text) {String}"
internal: true
internal: true
2 changes: 1 addition & 1 deletion src/WebAsyncWrapper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/WebClient.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 20 additions & 5 deletions src/WebHelpers.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
'
Expand Down