Making logger calls more optimal

This commit is contained in:
Pavel Shevaev 2022-11-08 14:11:00 +03:00
parent a7a7d38702
commit 90d54017d8
1 changed files with 10 additions and 6 deletions

View File

@ -14,12 +14,18 @@ type EventReceiver struct {
// Event receives a simple notification when various events occur
func (n *EventReceiver) Event(eventName string) {
if n.s.LogLevel == 0 {
return
}
n.logger.WithCallDepth(2).V(1).Info(eventName)
}
// EventKv receives a notification when various events occur along with
// optional key/value data
func (n *EventReceiver) EventKv(eventName string, kvs map[string]string) {
if n.s.LogLevel == 0 {
return
}
n.logger.WithCallDepth(2).V(1).Info(eventName)
}
@ -38,21 +44,19 @@ func (n *EventReceiver) Timing(eventName string, nanoseconds int64) {
// TimingKv receives the time an event took to happen along with optional key/value data
func (n *EventReceiver) TimingKv(eventName string, nanoseconds int64, kvs map[string]string) {
if n.s.LogLevel == 0 {
return
}
sql := kvs["sql"]
sp := strings.Index(sql, " ")
if sp != -1 {
query := sql[:sp]
if n.s.LogLevel > 1 {
n.logger.WithCallDepth(3).V(1).Info(sql)
} else {
if len(sql) > 50 {
sql = sql[:50] + "..."
}
if query == "SELECT" && n.s.LogLevel > 0 {
n.logger.WithCallDepth(3).V(1).Info(sql)
} else {
n.logger.WithCallDepth(3).V(1).Info(sql)
}
n.logger.WithCallDepth(3).V(1).Info(sql)
}
}
}