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
+12.2k Golang : Detect user location with HTML5 geo-location
+13.7k Golang : Tutorial on loading GOB and PEM files
+8.3k Golang : Auto-generate reply email with text/template package
+5.8k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+5.6k Python : Print unicode escape characters and string
+43.5k Golang : Get hardware information such as disk, memory and CPU usage
+13.5k Golang : Count number of runes in string
+14.7k Golang : Reset buffer example
+6.8k Golang : Muxing with Martini example
+43.3k Golang : Convert []byte to image
+32.7k Golang : Regular Expression for alphanumeric and underscore
+10.4k Golang : cannot assign type int to value (type uint8) in range error