Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2891

options.LogLevel is not 1-1 with LogSink

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.12.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      The level value returned by the Info function of a LogSink implementation will always be 1 less than the analogous options.LogLevel values.

      For example, options.LogLevelInfo is set to logger.LevelInfo, which is the 1 enumeration. The internal logger "Print" method will return 0 (logger.LevelInfo - logger.DiffToInfo). In general, the internal "Print" method returns the difference between the internal level and the "DiffToInfo" constant. This is to ensure that "Info" is the 0th "level", so as to sync the LogSink with the go-logr/logr library:

      Level V(0) is the default, and logger.V(0).Info() has the same meaning as logger.Info().

      Here is a gist that illustrates this problem.

      There are two notable solutions to this problem:

      (1) offset the stable api levels:

      const (
      	LogLevelInfo LogLevel = LogLevel(logger.LevelInfo - logger.DiffToInfo)
      	LogLevelDebug LogLevel = LogLevel(logger.LevelDebug - logger.DiffToInfo)
      )
      

      This would be a breaking change since users may already be offsetting these levels in custom LogSink implementations.

      (2) create a function that converts the level returned by the log sink to the stable API level.

            Assignee:
            preston.vasquez@mongodb.com Preston Vasquez
            Reporter:
            preston.vasquez@mongodb.com Preston Vasquez
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: