Can there be a way to disable logging?

Open
#528 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript

Research direction

Start from the exported Log object whose error(module, msg, isofile) calls isofile.onError; the request is a supported way to silence error-level output instead of reassigning Log.error, as the workaround does. See how Log is exported from the package entry point and where onError is invoked, then add a documented switch (a log level or quiet option) and cover it in the existing test suite. Done when a consumer can disable error logging through the public API without the monkey-patch shown here.

Written by the indexing model from the issue text.

Description

enhancement

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.

Dominant language
TypeScript
Stars
2.5k
Forks
390
Avg merge
1d 17h
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from gpac/mp4box.js

All issues in gpac/mp4box.js

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.