Skip to content

Instantly share code, notes, and snippets.

@EricRahm
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricRahm/d18098cdf93ffe7a8445 to your computer and use it in GitHub Desktop.
Save EricRahm/d18098cdf93ffe7a8445 to your computer and use it in GitHub Desktop.
PR_LOG level mappings

Currently:

typedef enum PRLogModuleLevel {
    PR_LOG_NONE = 0,                /* nothing */
    PR_LOG_ALWAYS = 1,              /* always printed */ <---- lies, damned lies
    PR_LOG_ERROR = 2,               /* error messages */
    PR_LOG_WARNING = 3,             /* warning messages */
    PR_LOG_DEBUG = 4,               /* debug messages */

    PR_LOG_NOTICE = PR_LOG_DEBUG,   /* notice messages */ this one's weird
    PR_LOG_WARN = PR_LOG_WARNING,   /* warning messages */ sigh whatever
    PR_LOG_MIN = PR_LOG_DEBUG,      /* minimal debugging messages */ wtf
    PR_LOG_MAX = PR_LOG_DEBUG       /* maximal debugging messages */ wtf
} PRLogModuleLevel;

Goal:

namespace mozilla {

enum class LogLevel {
  Disabled = 0, // Logging is disabled for this module
  Error,   // console => error()
  Warning, // console => warn()
  Info,    // console => info()
  Debug,   // console => debug (technically info)
};

}

So that gives us the following mappings:

Level PR_LOG Console Syslog
Error PR_LOG_ERROR console.error() error
Warning PR_LOG_WARNING console.warn() warning
Info n/a console.info() info
Debug PR_LOG_DEBUG console.debug()* debug

*console.debug => console.info

PR_LOG_ALWAYS

What happened to PR_LOG_ALWAYS?

  • It's a misnomer, the output is not always logged, only if that module's logging is enabled
  • A rough survey of usage indicates it should probably map to Info. Basically a level that is more than Debug, but not a warning and not an error.

How do we get rid of it?

  • Fact: only used in 44 files
  • Fact: shows up only once in 25 of those files
  • Fact: 15 of those instances are comment only mentions

So:

  1. For files with only a comment, just remove it, now we have 29
  2. For the other files with one instance, just make it Info, we now have 19
  3. For the rest do a brief triage, if it looks like it could just be Info make it Info, if it takes more than 10 seconds of thought make it Error

Verbose

What do we do with code that is emulating a Verbose level with PR_LOG_DEBUG + 1? Now that we have a level b/w Debug and Warn (Info) we can:

  1. Switch the usage of debug -> info
  2. Switch the usage of verbose -> debug

Swap out to LogLevel enum

  1. Add enum class, moz_test function, update MOZ_LOG
  2. Replace PRLogModuleLevel references w/ mozilla::LogLevel
  3. Replace any #define BLAH PR_LOG_(ERROR,WARNING,INFO,DEBUG,VERBOSE) w/ #define BLAH mozilla::LogLevel::
  4. Replace all remaining PR_LOG_(ERROR,WARNING,INFO,DEBUG,VERBOSE) w/ LogLevel::
  5. Unbreak namespace issues by adding using mozilla::LogLevel in broken files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment