Stream logs from syslog
This commit is contained in:
parent
02b93a3ef0
commit
f4481bca62
5 changed files with 287 additions and 5 deletions
32
internal/syslog/parser.go
Normal file
32
internal/syslog/parser.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package syslog
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ParseSyslogLine extracts the message content from a syslog line.
|
||||
// It looks for the daemon prefix in the line and returns the message after it.
|
||||
//
|
||||
// Example input: "Dec 2 02:01:33 tyet daemon.info iwd: Error loading /var/lib/iwd//nemuphone.psk"
|
||||
// Example output: "Error loading /var/lib/iwd//nemuphone.psk", true
|
||||
//
|
||||
// Returns the message and a boolean indicating if the line was successfully parsed.
|
||||
func ParseSyslogLine(line, daemonPrefix string) (string, bool) {
|
||||
// Find the daemon prefix in the line (e.g., "iwd:")
|
||||
idx := strings.Index(line, daemonPrefix)
|
||||
if idx == -1 {
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Extract everything after the daemon prefix
|
||||
message := line[idx+len(daemonPrefix):]
|
||||
|
||||
// Trim leading/trailing whitespace
|
||||
message = strings.TrimSpace(message)
|
||||
|
||||
if message == "" {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return message, true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue