Skip to content

Commit

Permalink
Syntax Highlighting (#17)
Browse files Browse the repository at this point in the history
Added proper markdown for github to color the Golang syntax.
  • Loading branch information
GrimTheReaper authored and Marius Sturm committed Aug 11, 2017
1 parent beee24d commit 7ebf4f5
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,42 @@ The easiest way to integrate graylog logging into your go app is by
having your `main` function (or even `init`) call `log.SetOutput()`.
By using an `io.MultiWriter`, we can log to both stdout and graylog -
giving us both centralized and local logs. (Redundancy is nice).

package main

import (
"flag"
"gopkg.in/Graylog2/go-gelf.v1/gelf"
"io"
"log"
"os"
)

func main() {
var graylogAddr string

flag.StringVar(&graylogAddr, "graylog", "", "graylog server addr")
flag.Parse()

if graylogAddr != "" {
gelfWriter, err := gelf.NewWriter(graylogAddr)
if err != nil {
log.Fatalf("gelf.NewWriter: %s", err)
}
// log to both stderr and graylog2
log.SetOutput(io.MultiWriter(os.Stderr, gelfWriter))
log.Printf("logging to stderr & graylog2@'%s'", graylogAddr)
``` golang
package main

import (
"flag"
"gopkg.in/Graylog2/go-gelf.v1/gelf"
"io"
"log"
"os"
)

func main() {
var graylogAddr string

flag.StringVar(&graylogAddr, "graylog", "", "graylog server addr")
flag.Parse()

if graylogAddr != "" {
gelfWriter, err := gelf.NewWriter(graylogAddr)
if err != nil {
log.Fatalf("gelf.NewWriter: %s", err)
}
// log to both stderr and graylog2
log.SetOutput(io.MultiWriter(os.Stderr, gelfWriter))
log.Printf("logging to stderr & graylog2@'%s'", graylogAddr)
}

// From here on out, any calls to log.Print* functions
// will appear on stdout, and be sent over UDP to the
// specified Graylog2 server.

log.Printf("Hello gray World")
// From here on out, any calls to log.Print* functions
// will appear on stdout, and be sent over UDP to the
// specified Graylog2 server.

// ...
}
log.Printf("Hello gray World")

// ...
}
```
The above program can be invoked as:

go run test.go -graylog=localhost:12201
Expand Down

0 comments on commit 7ebf4f5

Please sign in to comment.