Skip to content

Commit

Permalink
Log the packet format
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerflint committed Sep 25, 2018
1 parent 5a9a935 commit 97cb5dd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type (
Drain struct {
Type string `json:"type"` // type of service ("papertrail")
URI string `json:"endpoint"` // uri of endpoint "log6.papertrailapp.com:199900"
ID string `json:"id"` // id to identify this app with external logger
AuthKey string `json:"key,omitempty"` // key or user for authentication
AuthSecret string `json:"secret,omitempty"` // password or secret for authentication
}
Expand Down
2 changes: 1 addition & 1 deletion drain/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func AddDrain(d logvac.Drain) error {
drains["papertrail"].Close()
}
// pTrail, err := NewPapertrailClient("logs6.papertrailapp.com:19900")
pTrail, err := NewPapertrailClient(d.URI)
pTrail, err := NewPapertrailClient(d.URI, d.ID)
if err != nil {
return fmt.Errorf("Failed to create papertrail client - %s", err)
}
Expand Down
11 changes: 5 additions & 6 deletions drain/papertrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import (

// Papertrail drain implements the publisher interface for publishing logs to papertrail.
type Papertrail struct {
Conn io.WriteCloser // connection to forward logs through
ID string // the app id or name
Conn io.WriteCloser // connection to forward logs through
}

// NewPapertrailClient creates a new mist publisher
func NewPapertrailClient(uri string) (*Papertrail, error) {
config.Log.Info("Papertrail URI: %s", uri)
func NewPapertrailClient(uri, id string) (*Papertrail, error) {
addr, err := net.ResolveUDPAddr("udp", uri)
if err != nil {
return nil, fmt.Errorf("Failed to resolve papertrail address - %s", err.Error())
}
config.Log.Info("Papertrail address resolved IP: %s - Port: %d", addr.IP, addr.Port)

conn, err := net.DialUDP("udp", nil, addr)
if err != nil {
Expand All @@ -30,7 +29,7 @@ func NewPapertrailClient(uri string) (*Papertrail, error) {

config.Log.Info("Connection to papertrail endpoint established")

return &Papertrail{conn}, nil
return &Papertrail{Conn: conn, ID: id}, nil
}

// Init initializes a connection to mist
Expand All @@ -44,7 +43,7 @@ func (p *Papertrail) Init() error {

// Publish utilizes mist's Publish to "drain" a log message
func (p *Papertrail) Publish(msg logvac.Message) {
config.Log.Info("Write 'papertrail' -> %s", msg.Raw)
config.Log.Info("%v", msg)
p.Conn.Write(msg.Raw)
}

Expand Down

0 comments on commit 97cb5dd

Please sign in to comment.