mirror of
https://github.com/wneessen/logranger.git
synced 2024-11-22 12:50:50 +01:00
Process log messages asynchronously in server.go
Changed the processing of log messages to run in a separate go routine, improving the performance of the server. This update ensures efficient log processing by allowing multiple log messages to be processed concurrently. The function has also been refactored to not return an error as any issues should be contained within the routine call itself.
This commit is contained in:
parent
a26c565119
commit
dbe0c6fe3b
1 changed files with 4 additions and 5 deletions
|
@ -171,9 +171,8 @@ ReadLoop:
|
|||
continue ReadLoop
|
||||
}
|
||||
}
|
||||
if err = s.processMessage(lm); err != nil {
|
||||
s.log.Error("failed to process actions on log message", LogErrKey, err)
|
||||
}
|
||||
s.wg.Add(1)
|
||||
go s.processMessage(lm)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,7 +182,8 @@ ReadLoop:
|
|||
// The method first checks if the ruleset is not nil. If it is nil, no actions will be
|
||||
// executed. For each rule in the ruleset, it checks if the log message matches the
|
||||
// rule's regular expression.
|
||||
func (s *Server) processMessage(lm parsesyslog.LogMsg) error {
|
||||
func (s *Server) processMessage(lm parsesyslog.LogMsg) {
|
||||
defer s.wg.Done()
|
||||
if s.ruleset != nil {
|
||||
for _, r := range s.ruleset.Rule {
|
||||
if !r.Regexp.MatchString(lm.Message.String()) {
|
||||
|
@ -216,7 +216,6 @@ func (s *Server) processMessage(lm parsesyslog.LogMsg) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// setLogLevel sets the log level based on the value of `s.conf.Log.Level`.
|
||||
|
|
Loading…
Reference in a new issue