-
-
Save strootman/ce41dc0331937666a581 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment