ably-cocoa icon indicating copy to clipboard operation
ably-cocoa copied to clipboard

Include identity of component that emitted a log message, where applicable

Open lawrence-forooghian opened this issue 1 year ago • 1 comments

Background

Many of the log messages emitted by the SDK are emitted by a specific instance of a class.

We would like all such messages to include some generally-useful information about this instance.

Requirements

Each message logged by a class instance should include the following information:

  • the name of the class of the object
  • the address of the object

Logging API considerations (falls under #1617)

The above should be implemented in a way that is consistent throughout the codebase and which is easy to include in new log messages. This means exposing an internal logging API that helps us to emit this information.

I’d suggest embedding this information in the logger object — i.e. so that there is a 1-1 correspondence between logger instances and SDK object instances. This could, for example, be achieved by adding a method to ARTInternalLog for creating a new logger from an existing one, given some metadata, e.g. -[ARTInternalLog loggerForObject:(id)object].

Prior art

What I’m suggesting above is based on the way we do logging in the Asset Tracking SDK. When creating a new object, we also create a new InternalLogHandler instance which stores information about the object that created it (example).

Current state

Our existing log messages often include the address of the object that emitted them, but it is done in an ad-hoc fashion (i.e. needing to remember to include "RT: %p" at the start of the message). For example:

ARTLogWarn(self.logger, @"RT:%p connection \"%@\" has reconnected, but resume failed. Reattaching any attached channels", self, message.connectionId);

┆Issue is synchronized with this Jira Task by Unito

lawrence-forooghian avatar Apr 13 '23 17:04 lawrence-forooghian