[GODRIVER-3004] Create event-specific command logging components Created: 03/Oct/23  Updated: 09/Oct/23  Resolved: 09/Oct/23

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

Type: Improvement Priority: Unknown
Reporter: Preston Vasquez Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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   

There could be a need for a user to only log specific command events, rather than any command event. For example, logging all commands may cause performance issues and thus user only wants to log failed commands. To address this issue, this ticket suggests adding the following logging components:

  • LogComponentCommandFailed: log the "failed" subset of all commands
  • LogComponentCommandStarted: log the "started" subset of all commands
  • LogComponentCommandSucceeded: log the "succeeded" subset of all commands

The usage of this would be the following:

	loggerOptions := options.
		Logger().
		SetSink(sink).
		SetComponentLevel(options.LogComponentCommandFailed, options.LogLevelDebug).
		SetComponentLevel(options.LogComponentCommandStarted, options.LogLeveInfo)
 
	clientOptions := options.
		Client().
		ApplyURI("mongodb://localhost:27017").
		SetLoggerOptions(loggerOptions)

boris.dogadov@mongodb.com notes that "We don't want to overcomplicate things and have O(N) categories, where N is log messages."
 
The original intention is for this is to filter logs during post-processing, i.e.

func (logger *CustomLogger) Info(level int, msg string, _ ...interface{}) {
	logger.mu.Lock()
	defer logger.mu.Unlock()
 
	if msg == "Command failed" {
		// Log something
	}
}

The Go Driver could make this easier by exporting helper constants in the mongo package for specific message types:

	if msg == mongo.LogComponentCommandFailedMsg {
		// Log something
	}

It may aslo be helpful to add a more granular filtering API to the log options, i.e. a "FilterEvents()" method.



 Comments   
Comment by Matt Dale [ 09/Oct/23 ]

This ticket proposes that we create command-specific components. However, we should reject this for two reasons:

  1. Per boris, We don't want to overcomplicate things and have O(N) categories, where N is log messages.
  2. We don't want to re-construct event monitoring within the context of logging

It may be worth following up with better documentation to guide users when to use the monitoring vs logging features.

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