Created
January 13, 2016 23:46
-
-
Save yifan-gu/e343a66ffd46012df20d to your computer and use it in GitHub Desktop.
sdjournal example
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 ( | |
"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