[GODRIVER-2891] options.LogLevel is not 1-1 with LogSink Created: 06/Jul/23  Updated: 28/Oct/23  Resolved: 20/Jul/23

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.12.1

Type: Improvement Priority: Unknown
Reporter: Preston Vasquez Assignee: Preston Vasquez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

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?


 Description   

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.



 Comments   
Comment by Githook User [ 01/Aug/23 ]

Author:

{'name': 'Preston Vasquez', 'email': 'prestonvasquez@icloud.com', 'username': 'prestonvasquez'}

Message: GODRIVER-2891 Add documentation for log levels (#1312)

Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
Co-authored-by: Matt Dale <9760375+matthewdale@users.noreply.github.com>
Branch: release/1.12
https://github.com/mongodb/mongo-go-driver/commit/afb541910cef7e700c1d6062b1da434f3a3d72c6

Comment by Githook User [ 20/Jul/23 ]

Author:

{'name': 'Preston Vasquez', 'email': 'prestonvasquez@icloud.com', 'username': 'prestonvasquez'}

Message: GODRIVER-2891 Add documentation for log levels (#1312)

Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
Co-authored-by: Matt Dale <9760375+matthewdale@users.noreply.github.com>
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/ecd5980a3e5aa97886ffa089e4a46666dc8a5d0f

Generated at Thu Feb 08 08:39:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.