github.com/madlambda/nash@v0.2.2-0.20230113003044-f2284521680b/internal/sh/log.go (about)

     1  package sh
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  )
     7  
     8  // LogFn is the logger type
     9  type LogFn func(format string, args ...interface{})
    10  
    11  // NewLog creates a new nash logger
    12  func NewLog(ns string, enable bool) LogFn {
    13  	logger := log.New(os.Stderr, "", 0)
    14  
    15  	return func(format string, args ...interface{}) {
    16  		if enable {
    17  			logger.Printf("["+ns+"] "+format, args...)
    18  		}
    19  	}
    20  }