Skip to content

journal: ability to set flags for journal instance #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

taranovegor
Copy link

I needed to merge journals, which involves using the --merge flag when calling journalctl. Since I couldn't find a way to do this in the current implementation, I propose the following solution.

The structure JournalReaderConfig is augmented with a field Flags that contains an array of constants. If the Flags array is not empty, the method NewJournalWithFlags is called with the bitwise OR of the values in the array.

sdjournal.NewJournalReader(sdjournal.JournalReaderConfig{
    Since: time.Duration(-1) * time.Minute,
    Flags: []int{sdjournal.SD_JOURNAL_SYSTEM, sdjournal.SD_JOURNAL_CURRENT_USER},
})

Copy link
Collaborator

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rebase to pick up the latest CI changes.

}

// NewJournalWithFlags return a new Journal instance pointing to the local journal
// with a list of flags indicating the scope and type of entries that will be accessed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document that the flag values are defined as SD_JOURNAL_FLAG_ and must be bitwise ORed

@@ -48,6 +48,10 @@ type JournalReaderConfig struct {
// in this directory. The supplied path may be relative or absolute.
Path string

// If not nil, the journal instance will point to a journal with a list
// of flags indicating the scope and type of entries that will be accessed.
Flags []int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this an array? Just let the caller do the bitwise OR. I think the issue is that the default flag will be 0 but ensure we know a user explicitly set the flags converting it to pointer may be enough so *int,

Copy link
Collaborator

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taranovegor please let us know if you want to keep working on this.

@taranovegor
Copy link
Author

@taranovegor please let us know if you want to keep working on this.

Yes, I will continue working on this, but I won’t be able to do it ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants