diff --git a/config.go b/config.go index a30d856..c1b5a18 100644 --- a/config.go +++ b/config.go @@ -63,8 +63,9 @@ type Config struct { } type LogFile struct { - Path string - Tag string + Path string + Tag string + Severity syslog.Priority } func init() { @@ -309,18 +310,22 @@ func decodeLogFiles(f interface{}) ([]LogFile, error) { case map[interface{}]interface{}: var ( - tag string - path string + tag string + path string + severity syslog.Priority ) tag, _ = val["tag"].(string) path, _ = val["path"].(string) + severity_input, _ := val["severity"].(string) + severity, _ = syslog.Severity(severity_input) + 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, Severity: severity}) default: panic(vals) diff --git a/examples/log_files.yml.example.advanced b/examples/log_files.yml.example.advanced index 6321ecf..3de66a3 100644 --- a/examples/log_files.yml.example.advanced +++ b/examples/log_files.yml.example.advanced @@ -6,6 +6,7 @@ files: tag: site2/access_log - path: /var/log/httpd/site2/error_log tag: site2/error_log + severity: err # Note: valid severity includes: emerg, alert, crit, err, warn, notice, info, debug - /opt/misc/*.log - /home/**/*.log - /var/log/mysqld.log diff --git a/remote_syslog.go b/remote_syslog.go index fb8bc65..fa1ac48 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, file_severity syslog.Priority, whence int) { defer s.registry.Remove(file) t, err := follower.New(file, follower.Config{ @@ -111,6 +111,10 @@ func (s *Server) tailOne(file, tag string, whence int) { tag = path.Base(file) } + if file_severity == 0 { + file_severity = s.config.Severity + } + for { select { case line, ok := <-t.Lines(): @@ -136,7 +140,7 @@ func (s *Server) tailOne(file, tag string, whence int) { if !matchExps(l, s.config.ExcludePatterns) { s.logger.Write(syslog.Packet{ - Severity: s.config.Severity, + Severity: file_severity, Facility: s.config.Facility, Time: time.Now(), Hostname: s.logger.ClientHostname, @@ -181,6 +185,7 @@ func (s *Server) globFiles(firstPass bool) { for _, glob := range s.config.Files { tag := glob.Tag + severity := glob.Severity files, err := filepath.Glob(utils.ResolvePath(glob.Path)) if err != nil { @@ -206,7 +211,7 @@ func (s *Server) globFiles(firstPass bool) { } s.registry.Add(file) - go s.tailOne(file, tag, whence) + go s.tailOne(file, tag, severity, whence) } } }