For real sending logs to logstash agent
This commit is contained in:
parent
dfe725e655
commit
599128f837
@ -1,9 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -24,9 +26,25 @@ func newCrispyServer() *crispyServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *crispyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (me *crispyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
me.logstasher.Printf("%+v\n", r)
|
j, err := json.Marshal(r)
|
||||||
|
if err == nil {
|
||||||
|
me.logstasher.Println(string(j))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLogstashLogger() *log.Logger {
|
func newLogstashLogger() *log.Logger {
|
||||||
return log.New(os.Stderr, "", 0)
|
return log.New(&logstashWriter{}, "", 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
type logstashWriter struct{}
|
||||||
|
|
||||||
|
func (me *logstashWriter) Write(b []byte) (int, error) {
|
||||||
|
conn, err := net.Dial("tcp", ":55784")
|
||||||
|
if err == nil {
|
||||||
|
defer conn.Close()
|
||||||
|
fmt.Fprintf(conn, string(b))
|
||||||
|
} else {
|
||||||
|
fmt.Printf(string(b))
|
||||||
|
}
|
||||||
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user