github.com/waldiirawan/apm-agent-go/v2@v2.2.2/apmtest/recordlogger.go (about) 1 // Licensed to Elasticsearch B.V. under one or more contributor 2 // license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright 4 // ownership. Elasticsearch B.V. licenses this file to you under 5 // the Apache License, Version 2.0 (the "License"); you may 6 // not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, 12 // software distributed under the License is distributed on an 13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 // KIND, either express or implied. See the License for the 15 // specific language governing permissions and limitations 16 // under the License. 17 18 package apmtest // import "github.com/waldiirawan/apm-agent-go/v2/apmtest" 19 20 import "fmt" 21 22 // RecordLogger is an implementation of apm.Logger, recording log entries. 23 type RecordLogger struct { 24 Records []LogRecord 25 } 26 27 // Debugf logs debug messages. 28 func (l *RecordLogger) Debugf(format string, args ...interface{}) { 29 l.logf("debug", format, args...) 30 } 31 32 // Errorf logs error messages. 33 func (l *RecordLogger) Errorf(format string, args ...interface{}) { 34 l.logf("error", format, args...) 35 } 36 37 // Warningf logs error messages. 38 func (l *RecordLogger) Warningf(format string, args ...interface{}) { 39 l.logf("warning", format, args...) 40 } 41 42 func (l *RecordLogger) logf(level string, format string, args ...interface{}) { 43 l.Records = append(l.Records, LogRecord{ 44 Level: level, 45 Format: format, 46 Message: fmt.Sprintf(format, args...), 47 }) 48 } 49 50 // LogRecord holds the details of a log record. 51 type LogRecord struct { 52 // Level is the log level: "debug", "error", or "warning". 53 Level string 54 55 // Format is the log message format, like "Thingy did foo %d times". 56 Format string 57 58 // Message is the formatted message. 59 Message string 60 }