Skip to content

Instantly share code, notes, and snippets.

@stuart-warren
Last active March 5, 2016 03:07
Show Gist options
  • Save stuart-warren/240aaa21fa6f2d69457a to your computer and use it in GitHub Desktop.
Save stuart-warren/240aaa21fa6f2d69457a to your computer and use it in GitHub Desktop.
Golang read from systemd journal
package journal
// #cgo pkg-config: --cflags --libs libsystemd-journal
// #include <systemd/sd-journal.h>
import (
"C"
)
func New() (j *C.struct_sd_journal) {
j = new(C.struct_sd_journal)
C.sd_journal_open(&j, C.SD_JOURNAL_LOCAL_ONLY)
j.SeekNext()
return j
}
func (j *C.struct_sd_journal) Close() {
C.sd_journal_close(j)
}
func (j *C.struct_sd_journal) SeekNext() (r int) {
return int(C.sd_journal_next(j))
}
func (j *C.struct_sd_journal) SeekPrev() (r int) {
return int(C.sd_journal_previous(j))
}
func (j *C.struct_sd_journal) SeekHead() (r int) {
return int(C.sd_journal_seek_head(j))
}
func (j *C.struct_sd_journal) SeekTail() (r int) {
return int(C.sd_journal_seek_tail(j))
}
func (j *C.struct_sd_journal) GetCursor() (scursor string) {
var cursor *C.char
C.sd_journal_get_cursor(j, &cursor)
scursor = C.GoString(cursor)
return
}
@stuart-warren
Copy link
Author

@stuart-warren
Copy link
Author

@chrissnell
Copy link

Hey @stuart-warren, do you know how to statically link a binary built from this code? I'm trying to get a static journald reader for CoreOS, which--incredibly--does not supply libsystemd-journal.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment