sigs.k8s.io/cluster-api-provider-aws@v1.5.5/pkg/cloud/logs/logs.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package logs 18 19 import ( 20 "github.com/aws/aws-sdk-go/aws" 21 22 "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud" 23 ) 24 25 const ( 26 logWithHTTPHeader = 9 27 logWithHTTPBody = 10 28 ) 29 30 // GetAWSLogLevel will return the log level of an AWS Logger. 31 func GetAWSLogLevel(logger cloud.Logger) aws.LogLevelType { 32 if logger.V(logWithHTTPBody).Enabled() { 33 return aws.LogDebugWithHTTPBody 34 } 35 36 if logger.V(logWithHTTPHeader).Enabled() { 37 return aws.LogDebug 38 } 39 40 return aws.LogOff 41 } 42 43 // NewWrapLogr will create an AWS Logger wrapper. 44 func NewWrapLogr(logger cloud.Logger) aws.Logger { 45 return &logrWrapper{ 46 log: logger, 47 } 48 } 49 50 type logrWrapper struct { 51 log cloud.Logger 52 } 53 54 func (l *logrWrapper) Log(msgs ...interface{}) { 55 switch len(msgs) { 56 case 0: 57 return 58 case 1: 59 l.log.Info(msgs[0].(string)) 60 default: 61 l.log.Info(msgs[0].(string), msgs[:1]...) 62 } 63 }