Golang log.SetOutput() function example
package log
Golang log.SetOutput() function usage example
package main
import (
"log"
"os"
)
func main() {
// make sure log.txt
// use touch command to create if log.txt does not exist
logFile, err := os.OpenFile("log.txt", os.O_WRONLY, 0666)
if err != nil {
panic(err)
}
defer logFile.Close()
// direct all log messages to log.txt
log.SetOutput(logFile)
log.Println("First log message!")
}
Reference :
Advertisement
Something interesting
Tutorials
+8.1k Golang : How To Use Panic and Recover
+12.8k Golang : http.Get example
+35.3k Golang : Strip slashes from string example
+14.6k Golang : Missing Bazaar command
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+5.3k Swift : Convert string array to array example
+19.2k Golang : Execute shell command
+9.6k Golang : How to generate Code 39 barcode?
+6.5k Unix/Linux : How to get own IP address ?
+16.3k Golang : Find out mime type from bytes in buffer
+13.1k Golang : Convert(cast) uintptr to string example
+22.9k Golang : Test file read write permission example