summaryrefslogtreecommitdiff
path: root/src/journal/test-journal-stream.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-10-18 03:29:19 +0200
committerLennart Poettering <lennart@poettering.net>2012-10-18 03:35:18 +0200
commit3c1668da6202f1ead3d4d3981b89e9da1a0e98e3 (patch)
treed4e2785f1dac02c19797373bb4342354e1958e9d /src/journal/test-journal-stream.c
parent86b2e20a5e5abf222fb81edcb5d58d012e35cbaa (diff)
journal: add ability to list values a specified field can take in all entries of the journal
The new 'unique' API allows listing all unique field values that a field specified by a field name can take in all entries of the journal. This allows answering queries such as "What units logged to the journal?", "What hosts have logged into the journal?", "Which boot IDs have logged into the journal?". Ultimately this allows implementation of tools similar to lastlog based on journal data. Note that listing these field values will not work for journal files created with older journald, as the field values are not indexed in older files.
Diffstat (limited to 'src/journal/test-journal-stream.c')
-rw-r--r--src/journal/test-journal-stream.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c
index caea2b2c63..b3e816db70 100644
--- a/src/journal/test-journal-stream.c
+++ b/src/journal/test-journal-stream.c
@@ -77,6 +77,8 @@ int main(int argc, char *argv[]) {
unsigned i;
sd_journal *j;
char *z;
+ const void *data;
+ size_t l;
log_set_max_level(LOG_DEBUG);
@@ -124,12 +126,10 @@ int main(int argc, char *argv[]) {
assert_se(sd_journal_add_match(j, "MAGIC=quux", 0) >= 0);
SD_JOURNAL_FOREACH_BACKWARDS(j) {
- const void *d;
- size_t l;
char *c;
- assert_se(sd_journal_get_data(j, "NUMBER", &d, &l) >= 0);
- printf("\t%.*s\n", (int) l, (const char*) d);
+ assert_se(sd_journal_get_data(j, "NUMBER", &data, &l) >= 0);
+ printf("\t%.*s\n", (int) l, (const char*) data);
assert_se(sd_journal_get_cursor(j, &c) >= 0);
assert_se(sd_journal_test_cursor(j, c) > 0);
@@ -137,12 +137,10 @@ int main(int argc, char *argv[]) {
}
SD_JOURNAL_FOREACH(j) {
- const void *d;
- size_t l;
char *c;
- assert_se(sd_journal_get_data(j, "NUMBER", &d, &l) >= 0);
- printf("\t%.*s\n", (int) l, (const char*) d);
+ assert_se(sd_journal_get_data(j, "NUMBER", &data, &l) >= 0);
+ printf("\t%.*s\n", (int) l, (const char*) data);
assert_se(sd_journal_get_cursor(j, &c) >= 0);
assert_se(sd_journal_test_cursor(j, c) > 0);
@@ -175,6 +173,10 @@ int main(int argc, char *argv[]) {
verify_contents(j, 0);
+ assert_se(sd_journal_query_unique(j, "NUMBER") >= 0);
+ SD_JOURNAL_FOREACH_UNIQUE(j, data, l)
+ printf("%.*s\n", (int) l, (const char*) data);
+
sd_journal_close(j);
assert_se(rm_rf_dangerous(t, false, true, false) >= 0);