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

Add literal types and values for logger levels #2056

Open
wants to merge 2 commits into
base: 4.x
Choose a base branch
from

Commits on Nov 23, 2024

  1. Add literal type for logger.level string values

    By default, `logger.level` is set to "info," type: `string`, even though
    types/index.d.ts specifies that `level` should be type: `number`. This
    is confusing.
    
    Worse, setting `logger.level` in TypeScript will not allow a string to
    be used. A specific number must be provided, even though a string works
    because `lookupLevel` converts the given string to the correct number.
    So setting `logger.level` must be done in one of two unsatisfactory
    ways:
    
    * By using double assertion to lie to TypeScript, i.e., using a string
    with `as unknown as number`. This defeats the purpose of types.
    * By providing the exact index of the log level desired, which requires
    reading Handlebars' logger implementation to see that:
      * `debug` = 0
      * `info` = 1
      * `warn` = 2
      * `error` = 3
    
      Note that these numbers are not available in the keys that are defined
      in the types (`DEBUG`, `INFO`, `WARN`, and `ERROR`), since they are
      not actually defined in the logger itself.
    mb-realpage authored Nov 23, 2024
    Configuration menu
    Copy the full SHA
    b207520 View commit details
    Browse the repository at this point in the history
  2. Add log level constants to logger

    The types for `DEBUG`, `INFO`, `WARN`, and `ERROR` are present in the
    types `logger`, but not in the code. If they're in the types they should
    be in the code as well.
    mb-realpage authored Nov 23, 2024
    Configuration menu
    Copy the full SHA
    f0443c1 View commit details
    Browse the repository at this point in the history