September 2017
Intermediate to advanced
466 pages
9h 33m
English
This subsection will present a Go program that works on all Unix machines and sends data to the logging service in various ways. The name of the program is useSyslog.go, and it will be presented in four parts.
First, you will see the expected preamble:
package main import ( "fmt" "log" "log/syslog" "os" "path/filepath" )
You have to use the log package for logging and the log/syslog package for defining the logging facility and the logging level of your program.
The second part is the following:
func main() {
programName := filepath.Base(os.Args[0])
sysLog, e := syslog.New(syslog.LOG_INFO|syslog.LOG_LOCAL7, programName)
if e != nil {
log.Fatal(e)
}
sysLog.Crit("Crit: Logging in Go!")
The syslog.New() function call, ...
Read now
Unlock full access