From 97cb5dd85eaf80e2295d27d08f66d0339db9e5f3 Mon Sep 17 00:00:00 2001 From: Tyler Flint Date: Tue, 25 Sep 2018 16:03:10 -0600 Subject: [PATCH] Log the packet format --- core/core.go | 1 + drain/drain.go | 2 +- drain/papertrail.go | 11 +++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/core.go b/core/core.go index 796d0e5..76f559d 100644 --- a/core/core.go +++ b/core/core.go @@ -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 } diff --git a/drain/drain.go b/drain/drain.go index 9e77bef..d79b11a 100644 --- a/drain/drain.go +++ b/drain/drain.go @@ -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) } diff --git a/drain/papertrail.go b/drain/papertrail.go index 0abcce7..8270845 100644 --- a/drain/papertrail.go +++ b/drain/papertrail.go @@ -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 { @@ -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 @@ -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) }