Skip to content

Support different log levels for console vs external logging services #1650

@yangwooseong

Description

@yangwooseong

Describe the problem

Currently, setLogExtension and console output share the same log level configuration. When you set a log level using setLogLevel(), both console output and log extensions use the identical filtering criteria.

This creates a limitation where you cannot send detailed debug logs to external services while keeping console output clean (info level)

Describe the proposed solution

I'm unsure about the optimal implementation approach. One idea I have that doesn't trigger breaking change is to add a parameter (customLevel) to setLogExtension and modify the needLog conditional with an OR condition. I'd appreciate your thoughts on whether this approach would be appropriate.

// logger.ts
export function setLogExtension(extension: LogExtension, logger?: StructuredLogger, customLevel?: LogLevel) {
  const loggers = logger ? [logger] : livekitLoggers;

  loggers.forEach((logR) => {
    const originalFactory = logR.methodFactory;

    logR.methodFactory = (methodName, configLevel, loggerName) => {
      const rawMethod = originalFactory(methodName, configLevel, loggerName);

      const logLevel = LogLevel[methodName as LogLevelString];

      const needConsoleLog = logLevel >= configLevel && logLevel < LogLevel.silent;
      const needExtensionLog = customLevel !== undefined 
        ? (logLevel >= customLevel && logLevel < LogLevel.silent)  // extensionLog depending on customLevel
        : needConsoleLog;

      return (msg, context?: [msg: string, context: object]) => {
        if (needConsoleLog) {
          if (context) rawMethod(msg, context);
          else rawMethod(msg);
        }

        if (needExtensionLog) {
          extension(logLevel, msg, context);
        }
      };
    };
    logR.setLevel(logR.getLevel());
  });
}

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions