2
0

Add LogLevelFromString func

This commit is contained in:
Jack Christensen
2015-09-16 09:21:51 -05:00
parent 23c48c2f87
commit 51407590eb
+29
View File
@@ -2,6 +2,7 @@ package pgx
import (
"encoding/hex"
"errors"
"fmt"
)
@@ -54,6 +55,34 @@ func (l *connLogger) Error(msg string, ctx ...interface{}) {
l.logger.Error(msg, ctx...)
}
// Converts log level string to constant
//
// Valid levels:
// trace
// debug
// info
// warn
// error
// none
func LogLevelFromString(s string) (int, error) {
switch s {
case "trace":
return LogLevelTrace, nil
case "debug":
return LogLevelDebug, nil
case "info":
return LogLevelInfo, nil
case "warn":
return LogLevelWarn, nil
case "error":
return LogLevelError, nil
case "none":
return LogLevelNone, nil
default:
return 0, errors.New("invalid log level")
}
}
func logQueryArgs(args []interface{}) []interface{} {
logArgs := make([]interface{}, 0, len(args))