log.go 892 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package log
  2. import (
  3. "fmt"
  4. "time"
  5. "k8s.io/klog"
  6. )
  7. func Errorf(format string, a ...interface{}) {
  8. klog.Errorf(fmt.Sprintf("[Error] %s", format), a...)
  9. }
  10. func Warningf(format string, a ...interface{}) {
  11. klog.V(2).Infof(fmt.Sprintf("[Warning] %s", format), a...)
  12. }
  13. func Infof(format string, a ...interface{}) {
  14. klog.V(3).Infof(fmt.Sprintf("[Info] %s", format), a...)
  15. }
  16. func Profilef(format string, a ...interface{}) {
  17. klog.V(3).Infof(fmt.Sprintf("[Profiler] %s", format), a...)
  18. }
  19. func Debugf(format string, a ...interface{}) {
  20. klog.V(4).Infof(fmt.Sprintf("[Debug] %s", format), a...)
  21. }
  22. func Profile(start time.Time, name string) {
  23. elapsed := time.Since(start)
  24. Profilef("%s: %s", elapsed, name)
  25. }
  26. func ProfileWithThreshold(start time.Time, threshold time.Duration, name string) {
  27. elapsed := time.Since(start)
  28. if elapsed > threshold {
  29. Profilef("%s: %s", elapsed, name)
  30. }
  31. }