joao-r-reis commented on code in PR #1755:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1755#discussion_r2143451621


##########
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:
   ``` 
   // NewLogger creates a StructuredLogger that uses the standard library log 
package.
   //
   // This logger will write log messages in the following format:
   //
   //   <LOG_LEVEL> gocql: <message> <fields[0].Name>=<fields[0].Value> 
<fields[1].Name>=<fields[1].Value>
   //
   // LOG_LEVEL is always a 3 letter string:
   //   - DEBUG -> DBG
   //   - INFO -> INF
   //   - WARNING -> WRN
   //   - ERROR -> ERR
   //
   // Example:
   //
   //   INF gocql: Adding host (session initialization). host_addr=127.0.0.1 
host_id=a21dd06e-9e7e-4528-8ad7-039604e25e73
   ```



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