github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/util/log/logpb/test_utils.go (about) 1 // Copyright 2022 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package logpb 12 13 import ( 14 "github.com/cockroachdb/cockroachdb-parser/pkg/util/jsonbytes" 15 "github.com/cockroachdb/redact" 16 ) 17 18 // TestingStructuredLogEvent is an implementation of EventPayload for use in 19 // tests, in order to avoid importing the eventpb package. 20 type TestingStructuredLogEvent struct { 21 CommonEventDetails 22 Channel 23 Event string 24 } 25 26 var _ EventPayload = (*TestingStructuredLogEvent)(nil) 27 28 // CommonDetails is part of the EventPayload interface. 29 func (f TestingStructuredLogEvent) CommonDetails() *CommonEventDetails { 30 return &f.CommonEventDetails 31 } 32 33 // LoggingChannel is part of the EventPayload interface. 34 func (f TestingStructuredLogEvent) LoggingChannel() Channel { 35 return f.Channel 36 } 37 38 // AppendJSONFields is part of the EventPayload interface. 39 func (f TestingStructuredLogEvent) AppendJSONFields( 40 printComma bool, b redact.RedactableBytes, 41 ) (bool, redact.RedactableBytes) { 42 printComma, b = f.CommonEventDetails.AppendJSONFields(printComma, b) 43 if f.Event != "" { 44 if printComma { 45 b = append(b, ',') 46 } 47 printComma = true 48 b = append(b, "\"Event\":\""...) 49 b = append(b, redact.StartMarker()...) 50 b = redact.RedactableBytes(jsonbytes.EncodeString([]byte(b), string(redact.EscapeMarkers([]byte(f.Event))))) 51 b = append(b, redact.EndMarker()...) 52 b = append(b, '"') 53 } 54 return printComma, b 55 }