Skip to content

Instantly share code, notes, and snippets.

@Rubentxu
Forked from yifan-gu/getlogs.go
Created February 26, 2017 14:27
Show Gist options
  • Save Rubentxu/e64c3961e3c3708032f37ac623fdc949 to your computer and use it in GitHub Desktop.
Save Rubentxu/e64c3961e3c3708032f37ac623fdc949 to your computer and use it in GitHub Desktop.
sdjournal example
package main
import (
"fmt"
"io"
"github.com/coreos/go-systemd/sdjournal"
)
func main() {
jconf := sdjournal.JournalReaderConfig{
Path: "/var/lib/rkt/pods/run/7299dc2c-effb-4a85-99d2-81c65ac7fe04/stage1/rootfs/var/log/journal/",
Matches: []sdjournal.Match{
{
Field: sdjournal.SD_JOURNAL_FIELD_SYSTEMD_UNIT,
Value: "busybox.service", // ${APPNAME}.service
},
},
}
jr, err := sdjournal.NewJournalReader(jconf)
if err != nil {
panic(err)
}
//jr.Follow(nil, os.Stdout)
b := make([]byte, 64*1<<(10)) // 64KB.
for {
c, err := jr.Read(b)
if err != nil {
if err == io.EOF {
break
}
panic(err)
}
fmt.Print(string(b[:c]))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment