test-journal-send.c revision 037ee337f0f64bd35ced765f2e2d97f496d4e7c7
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/***
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2011 Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (at your option) any later version.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is distributed in the hope that it will be useful, but
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Lesser General Public License for more details.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering***/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include <systemd/sd-journal.h>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include <stdlib.h>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include <unistd.h>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering#include "log.h"
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint main(int argc, char *argv[]) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering char huge[4096*1024];
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
96aad8d15a324d0e956a4e5653a11a67b209b41aLennart Poettering log_set_max_level(LOG_DEBUG);
23c80348e656a4e6fd9ba8f17523a65b6fa349a0Kay Sievers
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_journal_print(LOG_INFO, "piepapo");
003dffde2c1b93afbc9aff24b277276f65424406Lennart Poettering
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering sd_journal_send("MESSAGE=foobar",
003dffde2c1b93afbc9aff24b277276f65424406Lennart Poettering "VALUE=%i", 7,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering NULL);
003dffde2c1b93afbc9aff24b277276f65424406Lennart Poettering
6482f6269c87d2249e52e889a63adbdd50f2d691Ronny Chevalier errno = ENOENT;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering sd_journal_perror("Foobar");
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_journal_perror("");
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering memset(huge, 'x', sizeof(huge));
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering memcpy(huge, "HUGE=", 5);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering char_array_0(huge);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_journal_send("MESSAGE=Huge field attached",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering huge,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering NULL);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_journal_send("MESSAGE=uiui",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "VALUE=A",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "VALUE=B",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "VALUE=C",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "SINGLETON=1",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "OTHERVALUE=X",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "OTHERVALUE=Y",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "WITH_BINARY=this is a binary value \a",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering NULL);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering syslog(LOG_NOTICE, "Hello World!");
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_journal_print(LOG_NOTICE, "Hello World");
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_journal_send("MESSAGE=Hello World!",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "MESSAGE_ID=52fb62f99e2c49d89cfbf9d6de5e3555",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "PRIORITY=5",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "HOME=%s", getenv("HOME"),
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "TERM=%s", getenv("TERM"),
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "PAGE_SIZE=%li", sysconf(_SC_PAGESIZE),
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "N_CPUS=%li", sysconf(_SC_NPROCESSORS_ONLN),
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering NULL);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sleep(1);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering return 0;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering}
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering