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

Add additional debug logs for better traceability #203

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jguz-pubnub
Copy link
Contributor

@jguz-pubnub jguz-pubnub commented Feb 14, 2025

feat(logger): add OSLogWriter as the recommended LogWriter to use

feat(logger): refine LogWriter protocol signature to support build-in Logger from the os framework

feat(logger): enhance object descriptions with CustomStringConvertible

feat(logger): add explanatory documentation for debug-level logging messages

Copy link

@mohitpubnub mohitpubnub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -75,7 +79,14 @@ class EffectDispatcher<Invocation: AnyEffectInvocation, Event, Dependencies>: Di
storageId id: String,
notify listener: DispatcherListener<Event>
) {
effectsCache.put(effect: effect, with: id)
effectsCache.put(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

let currentStateDescr = String(describing: currentState)
let newStateDescr = String(describing: newState)

PubNub.log.debug("Exiting \(currentStateDescr)", category: LogCategory.eventEngine.rawValue)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

return "No URL found in request"
}

var debugString = ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻


switch encryptionResult {
case .success:
PubNub.log.debug("Data encrypted successfully", category: LogCategory.crypto.rawValue)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻


@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
extension Logger {
static var subsystem: String { "com.pubnub"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@@ -96,11 +98,17 @@ final class Request {
self.requestOperator = MultiplexRequestOperator(operators: operators)
self.delegate = delegate

PubNub.log.debug("Request Created \(requestID) on \(router)")
PubNub.log.info(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@@ -254,14 +266,29 @@ final class Request {
}

func didResume(_ task: URLSessionTask) {
sessionStream?.emitRequest(self, didResume: task)
PubNub.log.debug(
"Sending HTTP request \(task.requestDescr()) for \(requestID)",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

.debug,
category: category,
message: message(),
date: date,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@@ -50,6 +50,10 @@ class EffectDispatcher<Invocation: AnyEffectInvocation, Event, Dependencies>: Di
notify listener: DispatcherListener<Event>
) {
invocations.forEach {
PubNub.log.debug(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be some trace level because level of verbosity would be insane on working Event Engine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the currently exposed interface wrt LogType:

public struct LogType: OptionSet, Equatable, Hashable, Sendable {
  public let rawValue: UInt32

  // Reserverd Log Types
  public static let none = LogType([])
  public static let debug = LogType(rawValue: 1 << 0)
  public static let info = LogType(rawValue: 1 << 1)
  public static let event = LogType(rawValue: 1 << 2)
  public static let warn = LogType(rawValue: 1 << 3)
  public static let error = LogType(rawValue: 1 << 4)
  public static let log = LogType(rawValue: 1 << 31)
  public static let all = LogType(rawValue: UInt32.max)

  public init(rawValue: UInt32) {
    self.rawValue = rawValue
  }
}

I see two possibilities:

  1. Treating debug level as a trace level. However, this might not be what you expect
  2. Add a new trace type with the following value (1 << 5) to not to break values introduced before

Regarding the second option, we could then replace all the PubNub.log.debug occurrences I introduced in the scope of this PR with PubNub.log.trace. Which option do you prefer?

let currentStateDescr = String(describing: currentState)
let newStateDescr = String(describing: newState)

PubNub.log.debug("Exiting \(currentStateDescr)", category: LogCategory.eventEngine.rawValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious about performance hit because of formatting which won't be used if logger is off. Should we have some kind of closure in this function which conditionally will be called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how exactly it should work under the hood. The message parameter for the PubNub.log.debug and simillar methods as well uses autoclosure, which means that a value evaluation will be deferred if needed. Anyway, I will double check it if it works as expected and let you know

@parfeon parfeon self-requested a review February 18, 2025 16:02
Copy link
Contributor

@parfeon parfeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants