Last active
March 5, 2016 03:07
-
-
Save stuart-warren/240aaa21fa6f2d69457a to your computer and use it in GitHub Desktop.
Golang read from systemd journal
This file contains 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 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 | |
} |
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
https://github.com/remerge/j2q/blob/master/service.go