Details
-
Improvement
-
Resolution: Won't Do
-
Unknown
-
None
-
None
-
None
-
None
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.