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

Node: New setLogEventListeners() utility to get log events #1448

Merged
merged 2 commits into from
Aug 30, 2024

Conversation

ibc
Copy link
Member

@ibc ibc commented Aug 29, 2024

Details

  • Instead of relying on DEBUG variable and stdout/stderr logs, an application may want to collect mediasoup generated logs and post them somewhere.
  • This PR exposes a new setLogEventListeners() function at mediasoup root module level.

Usage example

mediasoup.setLogEventListeners({
  ondebug: undefined,
  onwarn: (namespace: string, log: string) => {
    MyEnterpriseLogger.warn(`${namespace} ${log}`);
  },
  onerror: (namespace: string, log: string, error?: Error) => {
    if (error) {
      MyEnterpriseLogger.error(`${namespace} ${log}: ${error}`);
    } else {
      MyEnterpriseLogger.error(`${namespace} ${log}`);
    }
  }
});

Notes

  • This change forces us (the developers) to always call logger.debug() with a single string argument, same for logger.warn(), and call logger.error() with one string argument or also with a second and optional Error argument.
  • Personally I like this since this forced me to change some existing logs and use a consistent syntax in all them.

### Details

- Instead of relying on `DEBUG` variable and stdout/stderr logs, an application may want to collect mediasoup generated logs and post them somewhere.
- This PR exposed a new `setLogEventListeners()` function at mediasoup root module level.

### Usage example

```ts
mediasoup.setLogEventListeners({
  ondebug: undefined,
  onwarn: (namespace: string, log: string) => {
    MyEnterpriseLogger.warn(`${namespace} ${log}`);
  },
  onerror: (namespace: string, log: string, error?: Error) => {
    if (error) {
      MyEnterpriseLogger.error(`${namespace} ${log}: ${error}`);
    } else {
      MyEnterpriseLogger.error(`${namespace} ${log}`);
    }
  }
});
```
@ibc ibc requested a review from jmillan August 29, 2024 16:05
@ibc ibc merged commit 9fd1d5e into v3 Aug 30, 2024
52 checks passed
@ibc ibc deleted the node-emit-log-events branch August 30, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants