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

Add granular severity settings for log_files.yml #249

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
15 changes: 10 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ type Config struct {
}

type LogFile struct {
Path string
Tag string
Path string
Tag string
Severity syslog.Priority
}

func init() {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions examples/log_files.yml.example.advanced
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 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, file_severity syslog.Priority, whence int) {
defer s.registry.Remove(file)

t, err := follower.New(file, follower.Config{
Expand All @@ -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():
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down