secret-agent icon indicating copy to clipboard operation
secret-agent copied to clipboard

ability to capture logs from light client rather than logging them to console.log

Open GlenDC opened this issue 3 years ago • 12 comments

As far as I understand the Secret-Agent code, and I mind you that I'm still in the process of fully grasping the entire codebase, logs from all log levels end up at:

https://github.com/ulixee/secret-agent/blob/db3f3535636707ed2fd9c7f5dcc29f7d4bd07cc7/commons/Logger.ts#L47-L103

The problem with this is that from a light client there is no way for me to really capture those logs and send them back for my own purposes. Let me show you, if you will, how I currently make use of Secret-Agent.

I create my core as follows:

import Core from '@secret-agent/core';

await Core.start({
        coreServerPort: port,
});

For each use of the core I create a new agent as follows:

this.agent = new Agent({
        name: 'brorun-playground',
        userAgent,
        showReplay: false,
        connectionToCore: new RemoteConnectionToCore({
                host: coreAddress,
        }),
});

And then I make use of the agent directly (e.g. to go to a page, wait for stuff, interact with the dom) by using that this.agent.

At the end I also close the agent as follows:

await this.agent.close();

Now the problem is that the Core, which I imagine is started as a child process (haven't checked to be sure) is doing this logging but as we can see from the Logging code it logs directly to the console. The brute-force way would be to capture the logs, but this would not restrict itself to logs just for that one client but capture it all. I could than filter on sessionID but that seems dirty?

What would you recommend on getting these logs per agent? I don't think there is a way currently to do so, but would you be open to think about how we could handle that? Would it be something you would be willing to support (with the default still being that we just log it all directly to the console. E.g. a first initial kick-off for the proposal could be:

  • we attach the logger to an active session;
  • by default the logger's internal stream is streaming it to console.log (stdout?!)
  • however we could allow this to be buffered instead, and provide a command to the agent to get the logs, in a similar fashion that the agent can get the entire page's content.

Related to this question I also wonder what one can really do with await agent.sessionId. It seems to me that he code to actually get the replay via the official code is not really exposed (e.g. getSession etc). Is one expected to work directly with the undocumented SQL files? Not that it would help me for these purposes as it doesn't seems that the logs are stored in there?

GlenDC avatar Mar 29 '22 09:03 GlenDC