github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/tools/tlog/log.go (about)

     1  // Package tlog provides common logf and logln primitives for dev tools
     2  /*
     3   * Copyright (c) 2021-2022, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package tlog
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  	"testing"
    11  
    12  	"github.com/NVIDIA/aistore/cmn/cos"
    13  )
    14  
    15  func prependTime(msg string) string {
    16  	return fmt.Sprintf("[%s] %s", cos.FormatNowStamp(), msg)
    17  }
    18  
    19  func Logln(msg string) {
    20  	if testing.Verbose() {
    21  		fmt.Fprintln(os.Stdout, prependTime(msg))
    22  	}
    23  }
    24  
    25  func Logf(f string, a ...any) {
    26  	if testing.Verbose() {
    27  		fmt.Fprintf(os.Stdout, prependTime(f), a...)
    28  	}
    29  }
    30  
    31  func LogfCond(cond bool, f string, a ...any) {
    32  	if cond {
    33  		Logf(f, a...)
    34  	}
    35  }