jameshartig commented on code in PR #1755:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1755#discussion_r2141370363


##########
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:
   This could use some more documentation, maybe in a follow-up PR? Ideally we 
could show some examples of what the logs would look like so people wouldn't 
have to dig into the source code to see that it's `<LVL> gocql: <message> 
<k>=<v>...`



-- 
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

Reply via email to