github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/ChaparKhane/log.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package chaparkhane 4 5 import ( 6 "fmt" 7 "io/ioutil" 8 "os" 9 "path" 10 ) 11 12 // log hold logs until app running. 13 var log []byte 14 15 // Log will show log in standard console & append log to buffer to save them later. 16 func Log(a ...interface{}) { 17 // print error to stderr 18 fmt.Fprintf(os.Stderr, "%v\n", a) 19 // Append log to CodeGenerateLog for saving to achaemenid.log later. 20 log = append(log, fmt.Sprintf("%v\n", a)...) 21 } 22 23 // SaveLogToStorage use to make||flush to achaemenid.log if needed! 24 func SaveLogToStorage(saveLocation string) { 25 // TODO::: Check if achaemenid.log not exist create it || Flush old logs! 26 err := ioutil.WriteFile(path.Join(saveLocation, "achaemenid.log"), log, 0755) 27 if err != nil { 28 panic(fmt.Sprintf("Unable to write achaemenid.log: %v", err)) 29 } 30 }