github.com/NeowayLabs/nash@v0.2.2-0.20200127205349-a227041ffd50/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  }