2021-09-02 20:48:15 +02:00
|
|
|
package pionlog
|
2020-10-22 16:54:50 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
)
|
|
|
|
|
|
|
|
type logger struct {
|
|
|
|
logger zerolog.Logger
|
|
|
|
subsystem string
|
|
|
|
}
|
|
|
|
|
2020-11-01 16:09:48 +01:00
|
|
|
func (l logger) Trace(msg string) {
|
2020-11-14 14:52:15 +01:00
|
|
|
l.logger.Trace().Msg(strings.TrimSpace(msg))
|
2020-11-01 16:09:48 +01:00
|
|
|
}
|
2021-09-20 00:19:10 +02:00
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
func (l logger) Tracef(format string, args ...any) {
|
2020-11-14 14:52:15 +01:00
|
|
|
msg := fmt.Sprintf(format, args...)
|
|
|
|
l.logger.Trace().Msg(strings.TrimSpace(msg))
|
2020-11-01 16:09:48 +01:00
|
|
|
}
|
2021-09-20 00:19:10 +02:00
|
|
|
|
2020-11-01 16:09:48 +01:00
|
|
|
func (l logger) Debug(msg string) {
|
2020-11-14 14:52:15 +01:00
|
|
|
l.logger.Debug().Msg(strings.TrimSpace(msg))
|
2020-11-01 16:09:48 +01:00
|
|
|
}
|
2021-09-20 00:19:10 +02:00
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
func (l logger) Debugf(format string, args ...any) {
|
2020-11-14 14:52:15 +01:00
|
|
|
msg := fmt.Sprintf(format, args...)
|
|
|
|
l.logger.Debug().Msg(strings.TrimSpace(msg))
|
2020-11-01 16:09:48 +01:00
|
|
|
}
|
2021-09-20 00:19:10 +02:00
|
|
|
|
2020-10-22 16:54:50 +02:00
|
|
|
func (l logger) Info(msg string) {
|
2021-01-13 21:36:43 +01:00
|
|
|
if strings.Contains(msg, "duplicated packet") {
|
2020-10-22 16:54:50 +02:00
|
|
|
return
|
|
|
|
}
|
2021-01-13 21:36:43 +01:00
|
|
|
|
2020-11-14 14:52:15 +01:00
|
|
|
l.logger.Info().Msg(strings.TrimSpace(msg))
|
2020-10-22 16:54:50 +02:00
|
|
|
}
|
2021-09-20 00:19:10 +02:00
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
func (l logger) Infof(format string, args ...any) {
|
2020-10-22 16:54:50 +02:00
|
|
|
msg := fmt.Sprintf(format, args...)
|
2021-01-13 21:36:43 +01:00
|
|
|
if strings.Contains(msg, "duplicated packet") {
|
2020-10-22 16:54:50 +02:00
|
|
|
return
|
|
|
|
}
|
2021-01-13 21:36:43 +01:00
|
|
|
|
2020-11-14 14:52:15 +01:00
|
|
|
l.logger.Info().Msg(strings.TrimSpace(msg))
|
2020-10-22 16:54:50 +02:00
|
|
|
}
|
2021-09-20 00:19:10 +02:00
|
|
|
|
2020-11-01 16:09:48 +01:00
|
|
|
func (l logger) Warn(msg string) {
|
2020-11-14 14:52:15 +01:00
|
|
|
l.logger.Warn().Msg(strings.TrimSpace(msg))
|
2020-11-01 16:09:48 +01:00
|
|
|
}
|
2021-09-20 00:19:10 +02:00
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
func (l logger) Warnf(format string, args ...any) {
|
2020-11-14 14:52:15 +01:00
|
|
|
msg := fmt.Sprintf(format, args...)
|
|
|
|
l.logger.Warn().Msg(strings.TrimSpace(msg))
|
2020-11-01 16:09:48 +01:00
|
|
|
}
|
2021-09-20 00:19:10 +02:00
|
|
|
|
2020-11-01 16:09:48 +01:00
|
|
|
func (l logger) Error(msg string) {
|
2020-11-14 14:52:15 +01:00
|
|
|
l.logger.Error().Msg(strings.TrimSpace(msg))
|
2020-11-01 16:09:48 +01:00
|
|
|
}
|
2021-09-20 00:19:10 +02:00
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
func (l logger) Errorf(format string, args ...any) {
|
2020-11-14 14:52:15 +01:00
|
|
|
msg := fmt.Sprintf(format, args...)
|
|
|
|
l.logger.Error().Msg(strings.TrimSpace(msg))
|
2020-11-01 16:09:48 +01:00
|
|
|
}
|