Skip to content

Instantly share code, notes, and snippets.

@strootman
Forked from stuart-warren/journal.go
Created March 3, 2016 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strootman/ce41dc0331937666a581 to your computer and use it in GitHub Desktop.
Save strootman/ce41dc0331937666a581 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment