mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
feat: add log keys
This commit is contained in:
parent
1e7dc782c6
commit
eebf8d3b6e
18
log/fields_stream.go
Normal file
18
log/fields_stream.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.uber.org/zap"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
StreamQueueKey = "queue"
|
||||||
|
StreamSubjectKey = "subject"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FStreamQueue(queue string) zap.Field {
|
||||||
|
return zap.String(StreamQueueKey, queue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func FStreamSubject(name string) zap.Field {
|
||||||
|
return zap.String(StreamSubjectKey, name)
|
||||||
|
}
|
||||||
@ -98,23 +98,23 @@ func New(l *zap.Logger, name, addr string, opts ...Option) (*Stream, error) {
|
|||||||
// default options
|
// default options
|
||||||
natsOpts := append([]nats.Option{
|
natsOpts := append([]nats.Option{
|
||||||
nats.ErrorHandler(func(conn *nats.Conn, subscription *nats.Subscription, err error) {
|
nats.ErrorHandler(func(conn *nats.Conn, subscription *nats.Subscription, err error) {
|
||||||
l.Error("Nats server error", log.FError(err))
|
l.Error("nats error", log.FError(err), log.FStreamQueue(subscription.Queue), log.FStreamSubject(subscription.Subject))
|
||||||
}),
|
}),
|
||||||
nats.ClosedHandler(func(conn *nats.Conn) {
|
nats.ClosedHandler(func(conn *nats.Conn) {
|
||||||
if err := conn.LastError(); err != nil {
|
if err := conn.LastError(); err != nil {
|
||||||
l.Error("Closed connection to nats server", log.FError(err))
|
l.Error("nats closed", log.FError(err))
|
||||||
} else {
|
} else {
|
||||||
l.Info("Closed connection to nats server")
|
l.Debug("nats closed")
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
nats.ReconnectHandler(func(conn *nats.Conn) {
|
nats.ReconnectHandler(func(conn *nats.Conn) {
|
||||||
l.Info("Reconnected to nats server")
|
l.Debug("nats reconnected")
|
||||||
}),
|
}),
|
||||||
nats.DisconnectErrHandler(func(conn *nats.Conn, err error) {
|
nats.DisconnectErrHandler(func(conn *nats.Conn, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Error("Disconnected from nats server", log.FError(err))
|
l.Error("nats disconnected", log.FError(err))
|
||||||
} else {
|
} else {
|
||||||
l.Info("Disconnected from nats server")
|
l.Debug("nats disconnected")
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
nats.Timeout(time.Millisecond * 500),
|
nats.Timeout(time.Millisecond * 500),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user