github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edge/test/integration/utils/common/log.go (about)

     1  /*
     2  Copyright 2019 The KubeEdge 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 common
    18  
    19  import (
    20  	"fmt"
    21  	"time"
    22  
    23  	"github.com/onsi/ginkgo"
    24  )
    25  
    26  //Function to get time in millisec
    27  func nowStamp() string {
    28  	return time.Now().Format(time.StampMilli)
    29  }
    30  
    31  //functiont to log the Ginkgo framework logs
    32  func logf(level string, format string, args ...interface{}) {
    33  	fmt.Fprintf(ginkgo.GinkgoWriter, nowStamp()+": "+level+": "+format+"\n", args...)
    34  }
    35  
    36  //Funciton to log Filure logs
    37  func Fatalf(format string, args ...interface{}) {
    38  	msg := fmt.Sprintf(format, args...)
    39  	logf("FAIL", msg)
    40  	ginkgo.Fail(nowStamp()+": "+msg, 1)
    41  }
    42  
    43  //function for log level
    44  func Infof(format string, args ...interface{}) {
    45  	msg := fmt.Sprintf(format, args...)
    46  	logf("INFO", msg)
    47  }
    48  
    49  //Function to print the test case name and status of execution
    50  func PrintTestcaseNameandStatus() {
    51  	var testdesc ginkgo.GinkgoTestDescription
    52  	var Status string
    53  	testdesc = ginkgo.CurrentGinkgoTestDescription()
    54  	if testdesc.Failed == true {
    55  		Status = "FAILED"
    56  	} else {
    57  		Status = "PASSED"
    58  	}
    59  	Infof("TestCase:%40s     Status=%s", testdesc.TestText, Status)
    60  }