From 1495a4da2464c6b3be88d2dadd56f8c3b80a7d28 Mon Sep 17 00:00:00 2001 From: Tom Terrace Date: Wed, 24 Jul 2019 14:24:44 -0400 Subject: [PATCH] Add feature to append the base path to the tag --- config.go | 5 ++++- remote_syslog.go | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index fd30135..cc6a12a 100644 --- a/config.go +++ b/config.go @@ -65,6 +65,7 @@ type Config struct { type LogFile struct { Path string Tag string + AppendPath bool } func init() { @@ -312,16 +313,18 @@ func decodeLogFiles(f interface{}) ([]LogFile, error) { var ( tag string path string + appendPath bool ) tag, _ = val["tag"].(string) path, _ = val["path"].(string) + appendPath, _ = val["appendPath"].(bool) if path == "" { return files, fmt.Errorf("Invalid log file %#v", val) } - files = append(files, LogFile{Tag: tag, Path: path}) + files = append(files, LogFile{Tag: tag, Path: path, AppendPath: appendPath}) default: panic(vals) diff --git a/remote_syslog.go b/remote_syslog.go index bc1a697..9132081 100644 --- a/remote_syslog.go +++ b/remote_syslog.go @@ -93,7 +93,7 @@ func (s *Server) closing() bool { } // Tails a single file -func (s *Server) tailOne(file, tag string, whence int) { +func (s *Server) tailOne(file, tag string, whence int, appendPath bool) { defer s.registry.Remove(file) t, err := follower.New(file, follower.Config{ @@ -109,6 +109,8 @@ func (s *Server) tailOne(file, tag string, whence int) { if tag == "" { tag = path.Base(file) + } else if appendPath == true { + tag = tag + path.Base(file) } for { @@ -180,6 +182,7 @@ func (s *Server) globFiles(firstPass bool) { for _, glob := range s.config.Files { tag := glob.Tag + appendPath := glob.AppendPath files, err := filepath.Glob(utils.ResolvePath(glob.Path)) if err != nil { @@ -205,7 +208,7 @@ func (s *Server) globFiles(firstPass bool) { } s.registry.Add(file) - go s.tailOne(file, tag, whence) + go s.tailOne(file, tag, whence, appendPath) } } }