// Log is used by the different Tr1d1um services to
// keep track of incoming requests and their corresponding responses
Log is used by the different Tr1d1um services to
keep track of incoming requests and their corresponding responses
// Log is used by the different Tr1d1um services to // keep track of incoming requests and their corresponding responses
func Log(logger kitlog.Logger, reducedLoggingResponseCodes []int) kithttp.ServerFinalizerFunc {
	errorLogger := logging.Error(logger)
	return func(ctx context.Context, code int, r *http.Request) {
		tid, _ := ctx.Value(ContextKeyRequestTID).(string)
		transactionInfoLogger, transactionLoggerOk := ctx.Value(ContextKeyTransactionInfoLogger).(kitlog.Logger)
		if !transactionLoggerOk {
			var kvs = []interface{}{logging.MessageKey(), "transaction logger not found in context", "tid", tid}
			kvs, _ = candlelight.AppendTraceInfo(r.Context(), kvs)
			errorLogger.Log(kvs...)
			return
		}
		requestArrival, ok := ctx.Value(ContextKeyRequestArrivalTime).(time.Time)
		if ok {
			transactionInfoLogger = kitlog.WithPrefix(transactionInfoLogger, "duration", time.Since(requestArrival))
		} else {
			kvs := []interface{}{logging.ErrorKey(), "Request arrival not capture for transaction logger", "tid", tid}
			kvs, _ = candlelight.AppendTraceInfo(r.Context(), kvs)
			errorLogger.Log(kvs...)
		}
		includeHeaders := true
		response := response{Code: code}
		for _, responseCode := range reducedLoggingResponseCodes {
			if responseCode == code {
				includeHeaders = false
				break
			}
		}
		if includeHeaders {
			response.Headers = ctx.Value(kithttp.ContextKeyResponseHeaders)
		}
		transactionInfoLogger.Log("response", response)
	}
}
func Log ( logger kitlog . Logger , reducedLoggingResponseCodes [ ] int ) kithttp . ServerFinalizerFunc { errorLogger := logging . Error ( logger ) return func ( ctx context . Context , code int , r * http . Request ) { tid , _ := ctx . Value ( ContextKeyRequestTID ) . ( string ) transactionInfoLogger , transactionLoggerOk := ctx . Value ( ContextKeyTransactionInfoLogger ) . ( kitlog . Logger ) if ! transactionLoggerOk { var kvs = [ ] interface { } { logging . MessageKey ( ) , " " , " " , tid } kvs , _ = candlelight . AppendTraceInfo ( r . Context ( ) , kvs ) errorLogger . Log ( kvs ... ) return } requestArrival , ok := ctx . Value ( ContextKeyRequestArrivalTime ) . ( time . Time ) if ok { transactionInfoLogger = kitlog . WithPrefix ( transactionInfoLogger , " " , time . Since ( requestArrival ) ) } else { kvs := [ ] interface { } { logging . ErrorKey ( ) , " " , " " , tid } kvs , _ = candlelight . AppendTraceInfo ( r . Context ( ) , kvs ) errorLogger . Log ( kvs ... ) } includeHeaders := true response := response { Code : code } for _ , responseCode := range reducedLoggingResponseCodes { if responseCode == code { includeHeaders = false break } } if includeHeaders { response . Headers = ctx . Value ( kithttp . ContextKeyResponseHeaders ) } transactionInfoLogger . Log ( " " , response ) } }
Log is used by the different Tr1d1um services to
keep track of incoming requests and their corresponding responses
Log is used by the different Tr1d1um services to keep track of incoming requests and their corresponding responses