|
package main
|
An implementation of various logging strategies supported by this service.
|
|
Generated documentation is available at:
https://pkg.go.dev/github.com/RedHatInsights/ccx-notification-writer/
Documentation in literate-programming-style is available at:
https://redhatinsights.github.io/ccx-notification-writer/packages/logging.html
|
import (
"time"
"github.com/Shopify/sarama"
"github.com/rs/zerolog/log"
)
|
logMessageInfo function records log info about message consumed from given
topic, partition, and offset.
|
func logMessageInfo ( consumer * KafkaConsumer , originalMessage * sarama . ConsumerMessage , parsedMessage IncomingMessage , event string ) {
log . Info ( ) .
Int ( offsetKey , int ( originalMessage . Offset ) ) .
Int ( partitionKey , int ( originalMessage . Partition ) ) .
Str ( topicKey , consumer . Configuration . Topic ) .
Int ( organizationKey , int ( * parsedMessage . Organization ) ) .
Str ( clusterKey , string ( * parsedMessage . ClusterName ) ) .
Int ( versionKey , int ( parsedMessage . Version ) ) .
Msg ( event )
}
|
logUnparsedMessageError function records log info about consumed message
that can not be parsed.
|
func logUnparsedMessageError ( consumer * KafkaConsumer , originalMessage * sarama . ConsumerMessage , event string , err error ) {
log . Error ( ) .
Int ( offsetKey , int ( originalMessage . Offset ) ) .
Str ( topicKey , consumer . Configuration . Topic ) .
Err ( err ) .
Msg ( event )
}
|
logMessageError function records log info about consumed message that
contain (any) improper data.
|
func logMessageError ( consumer * KafkaConsumer , originalMessage * sarama . ConsumerMessage , parsedMessage IncomingMessage , event string , err error ) {
log . Error ( ) .
Int ( offsetKey , int ( originalMessage . Offset ) ) .
Str ( topicKey , consumer . Configuration . Topic ) .
Int ( organizationKey , int ( * parsedMessage . Organization ) ) .
Str ( clusterKey , string ( * parsedMessage . ClusterName ) ) .
Int ( versionKey , int ( parsedMessage . Version ) ) .
Err ( err ) .
Msg ( event )
}
|
logMessageWarning function records log info about consumed message that
contain (any) data that are not 100% correct.
|
func logMessageWarning ( consumer * KafkaConsumer , originalMessage * sarama . ConsumerMessage , parsedMessage IncomingMessage , event string ) {
log . Warn ( ) .
Int ( offsetKey , int ( originalMessage . Offset ) ) .
Int ( partitionKey , int ( originalMessage . Partition ) ) .
Str ( topicKey , consumer . Configuration . Topic ) .
Int ( organizationKey , int ( * parsedMessage . Organization ) ) .
Str ( clusterKey , string ( * parsedMessage . ClusterName ) ) .
Int ( versionKey , int ( parsedMessage . Version ) ) .
Msg ( event )
}
|
logDuration function records log info about duration of any task/process.
|
func logDuration ( tStart , tEnd time . Time , offset int64 , key string ) {
duration := tEnd . Sub ( tStart )
log . Info ( ) . Int64 ( durationKey , duration . Microseconds ( ) ) . Int64 ( offsetKey , offset ) . Msg ( key )
}
|