github.com/looshlee/beatles@v0.0.0-20220727174639-742810ab631c/pkg/flowdebug/flowdebug.go (about) 1 // Copyright 2018 Authors of Cilium 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package flowdebug 16 17 import ( 18 "github.com/sirupsen/logrus" 19 ) 20 21 var perFlowDebug = false 22 23 // Enable enables per-flow debugging 24 func Enable() { 25 perFlowDebug = true 26 } 27 28 // Enabled reports the status of per-flow debugging 29 func Enabled() bool { 30 return perFlowDebug 31 } 32 33 // Log must be used to log any debug messages emitted per request/message/connection 34 func Log(l *logrus.Entry, args ...interface{}) { 35 if perFlowDebug { 36 l.Debug(args...) 37 } 38 } 39 40 // Logf must be used to log any debug messages emitted per request/message/connection 41 func Logf(l *logrus.Entry, format string, args ...interface{}) { 42 if perFlowDebug { 43 l.Debugf(format, args...) 44 } 45 }