Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fortitudepub/4ee6344065508e9f35e6a4101c42bf6e to your computer and use it in GitHub Desktop.
Save fortitudepub/4ee6344065508e9f35e6a4101c42bf6e to your computer and use it in GitHub Desktop.
go json to syslog
package main
import (
"log"
"log/syslog"
"encoding/json"
"fmt"
)
type FunnyLog struct {
FunnyInt int `json:"funnyInt"`
FunnyBool bool `json:"funnyBool"`
FunnyString string `json:"funnyString"`
};
func main() {
logger, err := syslog.Dial("tcp", "192.168.99.133:514", syslog.LOG_ALERT | syslog.LOG_LOCAL0, "funnylog")
if err != nil {
log.Fatal("error to connect ekanite log server")
return
}
fLog := &FunnyLog{
FunnyInt: 10,
FunnyBool: true,
FunnyString: "I love funny log.",
}
fLogB, _ := json.Marshal(fLog)
fmt.Printf("log %v sent\n", string(fLogB))
logger.Alert(string(fLogB))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment