joao-r-reis commented on code in PR #1755: URL: https://github.com/apache/cassandra-gocql-driver/pull/1755#discussion_r2143409143
########## logger.go: ########## @@ -28,33 +28,346 @@ import ( "bytes" "fmt" "log" + "net" + "strconv" + "strings" + "sync" ) -type StdLogger interface { - Print(v ...interface{}) - Printf(format string, v ...interface{}) - Println(v ...interface{}) -} +// Deprecated: use StructuredLogger instead +type StdLogger interface{} type nopLogger struct{} -func (n nopLogger) Print(_ ...interface{}) {} +func (n nopLogger) Error(_ string, _ ...LogField) {} + +func (n nopLogger) Warning(_ string, _ ...LogField) {} + +func (n nopLogger) Info(_ string, _ ...LogField) {} -func (n nopLogger) Printf(_ string, _ ...interface{}) {} +func (n nopLogger) Debug(_ string, _ ...LogField) {} -func (n nopLogger) Println(_ ...interface{}) {} +var nopLoggerSingleton = &nopLogger{} type testLogger struct { - capture bytes.Buffer + logLevel LogLevel + capture bytes.Buffer + mu sync.Mutex +} + +func newTestLogger(logLevel LogLevel) *testLogger { + return &testLogger{logLevel: logLevel} +} + +func (l *testLogger) Error(msg string, fields ...LogField) { + if LogLevelError <= l.logLevel { + l.write("ERR gocql: ", msg, fields) + } +} + +func (l *testLogger) Warning(msg string, fields ...LogField) { + if LogLevelWarn <= l.logLevel { + l.write("WRN gocql: ", msg, fields) + } +} + +func (l *testLogger) Info(msg string, fields ...LogField) { + if LogLevelInfo <= l.logLevel { + l.write("INF gocql: ", msg, fields) + } +} + +func (l *testLogger) Debug(msg string, fields ...LogField) { + if LogLevelDebug <= l.logLevel { + l.write("DBG gocql: ", msg, fields) + } +} + +func (l *testLogger) write(prefix string, msg string, fields []LogField) { + buf := bytes.Buffer{} + writeLogMsg(&buf, prefix, msg, fields) + l.mu.Lock() + defer l.mu.Unlock() + l.capture.WriteString(buf.String() + "\n") +} + +func (l *testLogger) String() string { + l.mu.Lock() + defer l.mu.Unlock() + return l.capture.String() +} + +type defaultLogger struct { + logLevel LogLevel +} + +// NewLogger creates an StructuredLogger that uses the standard library "log" package. Review Comment: I'm definitely going to work on changing `doc.go` and `README.md` before the 2.0 release to ensure the documentation is up to date and to add information about new features but in this PR I can at least add some information here in this method to let the user know what the default logger will do. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org