custom vars via -var
This commit is contained in:
parent
429eb6b339
commit
36bb357b47
22
main.go
22
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -31,11 +32,26 @@ func udpConnect(addr string) (conn *net.UDPConn) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type mapFlag map[string]string
|
||||||
|
|
||||||
|
func (i *mapFlag) String() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
func (i *mapFlag) Set(v string) error {
|
||||||
|
s := strings.Split(v, "=")
|
||||||
|
if len(s) > 1 && s[0] != "" {
|
||||||
|
(*i)[s[0]] = strings.Join(s[1:], "=")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
socketFile := flag.String("socket", "/dev/log", "socket file")
|
socketFile := flag.String("socket", "/dev/log", "socket file")
|
||||||
stdoutTpl := flag.String("stdoutTpl", "[{{.timestamp}}] {{.content}}", "stdout line template, variables are: timestamp, content, facility, hostname, priority, severity, tag")
|
stdoutTpl := flag.String("stdoutTpl", "[{{.timestamp}}] {{.content}}", "stdout line template, variables are: timestamp, content, facility, hostname, priority, severity, tag")
|
||||||
udpAddr := flag.String("udpAddr", "", "udp address, format is host:port")
|
udpAddr := flag.String("udpAddr", "", "udp address, format is host:port")
|
||||||
udpTpl := flag.String("udpTpl", "{{ json . }}", "udp line template, see stdoutTpl for variables")
|
udpTpl := flag.String("udpTpl", "{{ json . }}", "udp line template, see stdoutTpl for variables")
|
||||||
|
customVars := make(mapFlag)
|
||||||
|
flag.Var(&customVars, "var", "custom variable, pe. type=error, can be used multiple times")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -76,6 +92,9 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os.Chmod(*socketFile, 0666)
|
||||||
|
|
||||||
err = server.Boot()
|
err = server.Boot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -83,6 +102,9 @@ func main() {
|
|||||||
|
|
||||||
go func(channel syslog.LogPartsChannel) {
|
go func(channel syslog.LogPartsChannel) {
|
||||||
for logParts := range channel {
|
for logParts := range channel {
|
||||||
|
for k, v := range customVars {
|
||||||
|
logParts[k] = v
|
||||||
|
}
|
||||||
stdoutTemplate.Execute(os.Stdout, logParts)
|
stdoutTemplate.Execute(os.Stdout, logParts)
|
||||||
udpChannel <- logParts
|
udpChannel <- logParts
|
||||||
// fmt.Println(logParts)
|
// fmt.Println(logParts)
|
||||||
|
Loading…
Reference in New Issue
Block a user