Proposal for logging context information

Hello,

In an environment where multiple devices and sessions are operating simultaneously, debugging issues that arise in custom drivers or plugins can be quite challenging, especially when trying to identify the relevant logs among a large volume of log entries. To address this issue, I propose a feature to include context information (request, session) in the log output, enabling us to group and view only the logs related to the specific HTTP request or session.

The idea is to utilize AsyncLocalStorage, a feature officially added in Node 16, to achieve this.
Since the AsyncLocalStorage feature can provide an isolated store for each asynchronous request, it allows context information to be shared globally across the code, including various submodules, through the store of the asynchronous context in which the logger is called. This eliminates the need to pass the current context information to the logger every time.

And when handling session creation requests almost simultaneously, this allows for detailed log differentiation. (Using JSON format for logging could further maximize this effect.)

I considered using the --log-context CLI arguments to enable this feature, but it may also be appropriate to separate it as an advanced option using environment variables.

Below is a simple implementation of the above idea.
feat: logging context information by kkb912002 · Pull Request #2 · kkb912002/appium (github.com)

I would appreciate your feedback.

Thanks for the idea @1195
I’ve partially implemented it in feat(appium): Add session signature to all logs by mykola-mokhnach · Pull Request #20202 · appium/appium · GitHub

1 Like

Thank you for actively considering this.
However, I believe that this feature would be more advantageous for debugging when there are overlapping long session creation processes.
Are you opposed to recording from the moment the sessionId is generated(uuidv4()) as much as possible?