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
+9.3k Golang : How to get ECDSA curve and parameters data?
+6.3k Apt-get to install and uninstall Golang
+9k Golang : automatically figure out array length(size) with three dots
+9k Golang : Capture text return from exec function example
+6.1k Golang : Dealing with backquote
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date
+5.4k Gogland : Datasource explorer
+6.3k Golang : How to get capacity of a slice or array?
+22.7k Golang : Set and Get HTTP request headers example
+14.4k Golang : How to filter a map's elements for faster lookup
+35.5k Golang : Smarter Error Handling with strings.Contains()