Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config option to append the filename to the tag #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type Config struct {
type LogFile struct {
Path string
Tag string
AppendPath bool
}

func init() {
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions remote_syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down