bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/syslog_unix.go (about)

     1  // +build !windows,!nacl,!plan9
     2  
     3  package main
     4  
     5  import (
     6  	"flag"
     7  	"log"
     8  	"log/syslog"
     9  )
    10  
    11  var noSyslog = flag.Bool("disable-syslog", false, "disables logging to syslog")
    12  
    13  func init() {
    14  	mains = append(mains, setSyslog)
    15  }
    16  
    17  func setSyslog() {
    18  	if *noSyslog || *flagDev || *flagTest {
    19  		return
    20  	}
    21  	w, err := syslog.New(syslog.LOG_LOCAL6|syslog.LOG_INFO, "bosun")
    22  	if err != nil {
    23  		log.Printf("could not open syslog: %v", err)
    24  		return
    25  	}
    26  	log.Println("enabling syslog")
    27  	log.SetOutput(w)
    28  }