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