sigs.k8s.io/cluster-api-provider-azure@v1.14.3/test/e2e/log.go (about)

     1  //go:build e2e
     2  // +build e2e
     3  
     4  /*
     5  Copyright 2021 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package e2e
    21  
    22  import (
    23  	"fmt"
    24  	"time"
    25  
    26  	"github.com/onsi/ginkgo/v2"
    27  )
    28  
    29  // This code was inspired from kubernetes/kubernetes, specifically https://github.com/oomichi/kubernetes/blob/master/test/e2e/framework/log.go
    30  
    31  func nowStamp() string {
    32  	return time.Now().Format(time.StampMilli)
    33  }
    34  
    35  func logf(level string, format string, args ...interface{}) {
    36  	fmt.Fprintf(ginkgo.GinkgoWriter, nowStamp()+": "+level+": "+format+"\n", args...)
    37  }
    38  
    39  // Logf prints info logs with a timestamp and formatting.
    40  func Logf(format string, args ...interface{}) {
    41  	logf("INFO", format, args...)
    42  }
    43  
    44  // LogWarningf prints warning logs with a timestamp and formatting.
    45  func LogWarningf(format string, args ...interface{}) {
    46  	logf("WARNING", format, args...)
    47  }
    48  
    49  // Log prints info logs with a timestamp.
    50  func Log(message string) {
    51  	logf("INFO", message)
    52  }
    53  
    54  // LogWarning prints warning logs with a timestamp.
    55  func LogWarning(message string) {
    56  	logf("WARNING", message)
    57  }