bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/slog/slog_unix.go (about)

     1  // +build !windows,!nacl,!plan9
     2  
     3  package slog
     4  
     5  import "log/syslog"
     6  
     7  // SetSyslog configures slog to use the system syslog daemon.
     8  func SetSyslog(tag string) error {
     9  	w, err := syslog.New(syslog.LOG_LOCAL6, tag)
    10  	if err != nil {
    11  		return err
    12  	}
    13  	Set(&Syslog{W: w})
    14  	return nil
    15  }
    16  
    17  // Syslog logs to syslog.
    18  type Syslog struct {
    19  	W *syslog.Writer
    20  }
    21  
    22  // Fatal logs a fatal message and calls os.Exit(1).
    23  func (s *Syslog) Fatal(v string) {
    24  	s.W.Crit("crit: " + v)
    25  }
    26  
    27  // Error logs an error message.
    28  func (s *Syslog) Error(v string) {
    29  	s.W.Err("error: " + v)
    30  }
    31  
    32  // Info logs an info message.
    33  func (s *Syslog) Info(v string) {
    34  	// Mac OSX ignores levels info and debug by default, so use notice.
    35  	s.W.Notice("info: " + v)
    36  }
    37  
    38  // Warning logs a warning message.
    39  func (s *Syslog) Warning(v string) {
    40  	s.W.Warning("warning: " + v)
    41  }