Skip to content

Can there be a way to disable logging? #528

@james-hu

Description

@james-hu

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions