mp4box.js icon indicating copy to clipboard operation
mp4box.js copied to clipboard

Can there be a way to disable logging?

Open james-hu opened this issue 2 months ago • 2 comments

Based on current code, there's no way to disable logging of error level messages. This is my hacky workaround:

/**
 * Suppress or restore Mp4Box error logging
 * @param mp4box Mp4Box module
 * @param quiet Whether to suppress error logging or restore original behaviour
 */
export function makeMp4BoxQuiet(mp4box: typeof import('mp4box'), quiet: boolean | undefined) {
  if (quiet) {
    (mp4box.Log as any).originalError = mp4box.Log.error;
    mp4box.Log.error = (module: string, msg?: string, isofile?: ISOFile) => {
      // This implementation is copied from mp4box source code
      if (isofile?.onError) {
        isofile.onError(module, msg ?? '');
      }
    };
  } else {
    const originalError = (mp4box.Log as any).originalError;
    if (originalError) {
      mp4box.Log.error = originalError;
    }
  }
}

I hope there's a better way to achieve this.

james-hu avatar Nov 25 '25 13:11 james-hu

If you'd like to send a PR, I'd be happy to review it. It should be pretty straightforward to add a quiet level to the logs.

DenizUgur avatar Nov 25 '25 16:11 DenizUgur

PR created.

james-hu avatar Nov 26 '25 00:11 james-hu