Add LogLevelFromString func
This commit is contained in:
@@ -2,6 +2,7 @@ package pgx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -54,6 +55,34 @@ func (l *connLogger) Error(msg string, ctx ...interface{}) {
|
|||||||
l.logger.Error(msg, ctx...)
|
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{} {
|
func logQueryArgs(args []interface{}) []interface{} {
|
||||||
logArgs := make([]interface{}, 0, len(args))
|
logArgs := make([]interface{}, 0, len(args))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user