papertrail / remote_syslog2

To install, see "Releases" tab. Self-contained daemon for reading local files and emitting remote syslog (without using local syslogd).
http://help.papertrailapp.com/
MIT License
637 stars 157 forks source link

Create an includes_patterns for explicit log lines #220

Open shadowbq opened 5 years ago

shadowbq commented 5 years ago

There are situations where we dont want the entire log file, (catalina/tomcat) to dump into remote syslog.

I know there was a previous issue thar was complicated, but this could just be implemented with a config that fails if both includes_patterns and excludes_patterns both exist to at least add value.

shadowbq commented 5 years ago
type Config struct {        
    [..]
    IncludePatterns      []*regexp.Regexp `mapstructure:"include_patterns"`
    [..]
}
    if ( s.config.IncludePatterns blah blah is set )
        {
            if matchExps(l, s.config.IncludePatterns) {

                s.logger.Write(syslog.Packet{
                    Severity: s.config.Severity,
                    Facility: s.config.Facility,
                    Time:     time.Now(),
                    Hostname: s.logger.ClientHostname,
                    Tag:      tag,
                    Message:  l,
                })

                log.Tracef("Forwarding line: %s", l)

            } else {
                log.Tracef("Not Forwarding line: %s", l)
            }
        }
    else 
        {
            if !matchExps(l, s.config.ExcludePatterns) {

                s.logger.Write(syslog.Packet{
                    Severity: s.config.Severity,
                    Facility: s.config.Facility,
                    Time:     time.Now(),
                    Hostname: s.logger.ClientHostname,
                    Tag:      tag,
                    Message:  l,
                })

                log.Tracef("Forwarding line: %s", l)

            } else {
                log.Tracef("Not Forwarding line: %s", l)
            }
        }