github.com/blystad/deis@v0.11.0/logger/syslog/message.go (about)

     1  package syslog
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  	"time"
     7  )
     8  
     9  // Message defines an RFC 3164 syslog message.
    10  type Message struct {
    11  	Time      time.Time // time the message was logged
    12  	Source    net.Addr  // source address of the log message
    13  	Facility            // facility tag (see type Facility)
    14  	Severity            // severity tag (see type Severity)
    15  	Timestamp time.Time // optional
    16  	Hostname  string    // optional
    17  	Tag       string    // message tag as defined in RFC 3164
    18  	Content   string    // message content as defined in RFC 3164
    19  	Tag1      string    // alternate message tag (white rune as separator)
    20  	Content1  string    // alternate message content (white rune as separator)
    21  }
    22  
    23  // NetSrc only network part of Source as string (IP for UDP or Name for UDS)
    24  func (m *Message) NetSrc() string {
    25  	switch a := m.Source.(type) {
    26  	case *net.UDPAddr:
    27  		return a.IP.String()
    28  	case *net.UnixAddr:
    29  		return a.Name
    30  	case *net.TCPAddr:
    31  		return a.IP.String()
    32  	}
    33  	// Unknown type
    34  	return m.Source.String()
    35  }
    36  
    37  // String returns the Message in a string format. This satisfies the fmt.Stringer
    38  // interface.
    39  func (m *Message) String() string {
    40  	timeLayout := "2006-01-02 15:04:05"
    41  	return fmt.Sprintf(
    42  		"%s %s %s%s",
    43  		m.Time.Format(timeLayout),
    44  		m.Hostname,
    45  		m.Tag,
    46  		m.Content,
    47  	)
    48  }