Tutorial by Examples

Go has a built-in logging library known as log with a commonly use method Print and its variants. You can import the library then do some basic printing: package main import "log" func main() { log.Println("Hello, world!") // Prints 'Hello, world!' on a single ...
It is possible to specify log destination with something that statisfies io.Writer interface. With that we can log to file: package main import ( "log" "os" ) func main() { logfile, err := os.OpenFile("test.log", os.O_RDWR|os.O_CREATE|os.O_APPEND,...
It is also possible to log to syslog with log/syslog like this: package main import ( "log" "log/syslog" ) func main() { syslogger, err := syslog.New(syslog.LOG_INFO, "syslog_example") if err != nil { log.Fatalln(err) } l...

Page 1 of 1