Created
August 7, 2018 05:57
-
-
Save fortitudepub/4ee6344065508e9f35e6a4101c42bf6e to your computer and use it in GitHub Desktop.
go json to syslog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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