コード例 #1
0
ファイル: journal.go プロジェクト: mheese/go-systemd
// SeekCursor seeks to the entry located at the specified cursor string. If no entry
// matching the specified cursor is found the call will seek to the next closest entry
// (in terms of time) instead. SeekCursor returns true if it was able to seek to the
// exact postion, or false, if it was able to only seek to the next closest position.
// It returns an error if the operation failed completely
func (j *Journal) SeekCursor(cursor string) error {
	ccursor := C.CString(cursor)
	defer C.free(unsafe.Pointer(ccursor))

	j.mu.Lock()
	r := C.sd_journal_seek_cursor(j.cjournal, ccursor)
	j.mu.Unlock()

	if r < 0 {
		return fmt.Errorf("failed to seek to cursor '%s': %d", cursor, r)
	}

	return nil
}
コード例 #2
0
ファイル: service.go プロジェクト: teh/elastic-journald
func (s *Service) InitJournal() {
	r := C.sd_journal_open(&s.Journal, C.SD_JOURNAL_LOCAL_ONLY)
	if r < 0 {
		panic(fmt.Sprintf("failed to open journal: %s", C.strerror(-r)))
	}

	bytes, err := ioutil.ReadFile(*elasticCursorFile)
	if err == nil {
		s.Cursor = string(bytes)
	}

	if s.Cursor != "" {
		r = C.sd_journal_seek_cursor(s.Journal, C.CString(s.Cursor))
		if r < 0 {
			panic(fmt.Sprintf("failed to seek journal: %s", C.strerror(-r)))
		}
		r = C.sd_journal_next_skip(s.Journal, 1)
		if r < 0 {
			panic(fmt.Sprintf("failed to skip current journal entry: %s", C.strerror(-r)))
		}
	}
}
コード例 #3
0
ファイル: service.go プロジェクト: iavael/elastic-journald
func (s *Service) InitJournal() {
	r := C.sd_journal_open(&s.Journal, C.SD_JOURNAL_LOCAL_ONLY)
	if r < 0 {
		log.Fatalf("failed to open journal: %s\n", C.strerror(-r))
	}

	bytes, err := ioutil.ReadFile(s.Config.State)
	if err == nil {
		s.Cursor = string(bytes)
	}

	if s.Cursor != "" {
		r = C.sd_journal_seek_cursor(s.Journal, C.CString(s.Cursor))
		if r < 0 {
			log.Fatalf("failed to seek journal: %s\n", C.strerror(-r))
		}
		r = C.sd_journal_next_skip(s.Journal, 1)
		if r < 0 {
			log.Fatalf("failed to skip current journal entry: %s\n", C.strerror(-r))
		}
	}
}