ORG.FREE...OGCONTROL1(5)

๐Ÿ’– org.freedesktop.LogControl1(5) โ€” the manual page, but make it a group chat ๐Ÿ’–

okay bestie, gather round, because today we're talking about org.freedesktop.LogControl1 โ€” a D-Bus interface that lets you peek at and poke your daemon's logging config. it's giving "admin energy" and honestly? iconic. let's get into it ๐Ÿฆ‹


โœจ NAME โœจ

org.freedesktop.LogControl1 โ€” the D-Bus interface for querying and setting logging configuration. no cap, that's literally it.


๐ŸŒธ INTRODUCTION ๐ŸŒธ

so org.freedesktop.LogControl1 is a generic interface โ€” meaning it's the blueprint, the template, the main character โ€” intended to be used by any daemon that wants to let you set the log level and the log target over D-Bus. a bunch of daemons that are part of the systemd(1) suite implement it. slay. ๐Ÿ‘‘

here's the tea: it's assumed those settings are global for the whole program, so there's just one fixed object path. no per-object nonsense. and that interface should always be available under the path:

/org/freedesktop/LogControl1

periodt. ๐Ÿ’…


๐ŸŽ€ DESCRIPTION ๐ŸŽ€

here's the interface being exposed, in all its glory โ€” copy it exactly, don't touch a single character, it's precious:

node /org/freedesktop/LogControl1 {
  interface org.freedesktop.LogControl1 {
    properties:
      @org.freedesktop.DBus.Property.EmitsChangedSignal("false")
      @org.freedesktop.systemd1.Privileged("true")
      readwrite s LogLevel = '...';
      @org.freedesktop.DBus.Property.EmitsChangedSignal("false")
      @org.freedesktop.systemd1.Privileged("true")
      readwrite s LogTarget = '...';
      @org.freedesktop.DBus.Property.EmitsChangedSignal("false")
      readonly s SyslogIdentifier = '...';
  };
  interface org.freedesktop.DBus.Peer { ... };
  interface org.freedesktop.DBus.Introspectable { ... };
  interface org.freedesktop.DBus.Properties { ... };
};

like, look at those annotations. EmitsChangedSignal("false") โ€” she does NOT gossip. Privileged("true") โ€” she has standards. we stan a secure interface ๐Ÿซถ

๐Ÿ”ฅ Properties ๐Ÿ”ฅ

okay so the properties are the whole point, let's break them down one by one:

  • LogLevel โ€” this one describes the syslog(3)-style log level, and it should be one of "emerg", "alert", "crit", "err", "warning", "notice", "info", "debug" โ€” and yes, that's in order of increasing verbosity. so "emerg" is the quietest "everything is on fire" moment and "debug" is the "tell me EVERYTHING, I want the drama" setting. ๐Ÿ˜ญ
  • LogTarget โ€” this is the log target, aka the mechanism, aka where do the messages actually go. it should be one of:
    • "console" โ€” log to the console or standard output
    • "kmsg" โ€” log to the kernel ring buffer
    • "journal" โ€” log to the journal natively, see systemd-journald.service(8)
    • "syslog" โ€” log using the syslog(3) call

๐Ÿ” Write Access ๐Ÿ”

okay this part is important, bestie, don't skim it.

the LogLevel and LogTarget properties are supposed to be writable. which means anyone who can write them can change your logging. so: care should be taken to ensure that only appropriately privileged clients can modify them. do not let just anybody in. this is a velvet rope situation. ๐Ÿ’€


back to properties, one more:

  • SyslogIdentifier โ€” this one is read-only (she's an observer, not a participant โœจ). it shows the "syslog identifier" โ€” a short little string that identifies the program that is the source of the log messages, and it's the thing that gets passed to the syslog(3) call.

๐Ÿ› ๏ธ TOOLS ๐Ÿ› ๏ธ

so you've got the interface, now how do you actually use it? glad you asked ๐Ÿงš

  • journalctl option -p/--priority= may be used to filter log messages by log level.
  • journalctl option -t/--identifier= may be used to filter by the syslog identifier.
  • filters like "_TRANSPORT=syslog", "_TRANSPORT=journal", and "_TRANSPORT=kernel" may be used to filter messages by the mechanism through which they reached systemd-journald.

and for the systemctl girlies:

  • systemctl log-level and systemctl log-target verbs may be used to query and set the LogLevel and LogTarget properties of the service manager.
  • systemctl service-log-level and systemctl service-log-target may similarly be used for individual services.
heads up though: for that last one, services must have the BusName= property set and must implement the interface described here. if they don't? no dice. ๐Ÿ™ˆ

see systemd.service(5) for all the details about BusName=. iykyk.


โœจ EXAMPLE โœจ

๐Ÿ’– Example 1. Create a simple listener on the bus that implements LogControl1

okay bestie, buckle up, this is the whole thing, ready to compile, no cap. it's giving "i'm a real D-Bus service and i do LogControl1" ๐Ÿซถ

/* SPDX-License-Identifier: MIT-0 */

/* Implements the LogControl1 interface as per specification:
 * https://www.freedesktop.org/software/systemd/man/org.freedesktop.LogControl1.html
 *
 * Compile with 'cc logcontrol-example.c $(pkg-config --libs --cflags libsystemd)'
 *
 * To get and set properties via busctl:
 *
 * $ busctl --user get-property org.freedesktop.Example \
 *                              /org/freedesktop/LogControl1 \
 *                              org.freedesktop.LogControl1 \
 *                              SyslogIdentifier
 *   s "example"
 * $ busctl --user get-property org.freedesktop.Example \
 *                              /org/freedesktop/LogControl1 \
 *                              org.freedesktop.LogControl1 \
 *                              LogTarget
 *   s "journal"
 * $ busctl --user get-property org.freedesktop.Example \
 *                              /org/freedesktop/LogControl1 \
 *                              org.freedesktop.LogControl1 \
 *                              LogLevel
 *   s "info"
 * $ busctl --user set-property org.freedesktop.Example \
 *                              /org/freedesktop/LogControl1 \
 *                              org.freedesktop.LogControl1 \
 *                              LogLevel \
 *                              "s" debug
 * $ busctl --user get-property org.freedesktop.Example \
 *                              /org/freedesktop/LogControl1 \
 *                              org.freedesktop.LogControl1 \
 *                              LogLevel
 *   s "debug"
 */

#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <syslog.h>
#include <systemd/sd-bus.h>
#include <systemd/sd-journal.h>

#define _cleanup_(f) __attribute__((cleanup(f)))

static int log_error(int log_level, int error, const char *str) {
  sd_journal_print(log_level, "%s failed: %s", str, strerror(-error));
  return error;
}

typedef enum LogTarget {
  LOG_TARGET_JOURNAL,
  LOG_TARGET_KMSG,
  LOG_TARGET_SYSLOG,
  LOG_TARGET_CONSOLE,
  _LOG_TARGET_MAX,
} LogTarget;

static const char* const log_target_table[_LOG_TARGET_MAX] = {
  [LOG_TARGET_JOURNAL] = "journal",
  [LOG_TARGET_KMSG]    = "kmsg",
  [LOG_TARGET_SYSLOG]  = "syslog",
  [LOG_TARGET_CONSOLE] = "console",
};

static const char* const log_level_table[LOG_DEBUG + 1] = {
  [LOG_EMERG]   = "emerg",
  [LOG_ALERT]   = "alert",
  [LOG_CRIT]    = "crit",
  [LOG_ERR]     = "err",
  [LOG_WARNING] = "warning",
  [LOG_NOTICE]  = "notice",
  [LOG_INFO]    = "info",
  [LOG_DEBUG]   = "debug",
};

typedef struct object {
  const char *syslog_identifier;
  LogTarget log_target;
  int log_level;
} object;

static int property_get(
                sd_bus *bus,
                const char *path,
                const char *interface,
                const char *property,
                sd_bus_message *reply,
                void *userdata,
                sd_bus_error *error) {

  object *o = userdata;

  if (strcmp(property, "LogLevel") == 0)
    return sd_bus_message_append(reply, "s", log_level_table[o->log_level]);

  if (strcmp(property, "LogTarget") == 0)
    return sd_bus_message_append(reply, "s", log_target_table[o->log_target]);

  if (strcmp(property, "SyslogIdentifier") == 0)
    return sd_bus_message_append(reply, "s", o->syslog_identifier);

  return sd_bus_error_setf(error,
                           SD_BUS_ERROR_UNKNOWN_PROPERTY,
                           "Unknown property '%s'",
                           property);
}

static int property_set(
                sd_bus *bus,
                const char *path,
                const char *interface,
                const char *property,
                sd_bus_message *message,
                void *userdata,
                sd_bus_error *error) {

  object *o = userdata;
  const char *value;
  int r;

  r = sd_bus_message_read(message, "s", &value);
  if (r < 0)
    return r;

  if (strcmp(property, "LogLevel") == 0) {
    int i;
    for (i = 0; i < LOG_DEBUG + 1; i++)
      if (strcmp(value, log_level_table[i]) == 0) {
        o->log_level = i;
        setlogmask(LOG_UPTO(i));
        return 0;
      }

    return sd_bus_error_setf(error,
                             SD_BUS_ERROR_INVALID_ARGS,
                             "Invalid value for LogLevel: '%s'",
                             value);
  }

  if (strcmp(property, "LogTarget") == 0) {
    LogTarget i;
    for (i = 0; i < _LOG_TARGET_MAX; i++)
      if (strcmp(value, log_target_table[i]) == 0) {
        o->log_target = i;
        return 0;
      }

    return sd_bus_error_setf(error,
                             SD_BUS_ERROR_INVALID_ARGS,
                             "Invalid value for LogTarget: '%s'",
                             value);
  }

  return sd_bus_error_setf(error,
                           SD_BUS_ERROR_UNKNOWN_PROPERTY,
                           "Unknown property '%s'",
                           property);
}

/* https://www.freedesktop.org/software/systemd/man/sd_bus_add_object.html
 */
static const sd_bus_vtable vtable[] = {
  SD_BUS_VTABLE_START(0),
  SD_BUS_WRITABLE_PROPERTY(
    "LogLevel", "s",
    property_get, property_set,
    0,
    0),
  SD_BUS_WRITABLE_PROPERTY(
    "LogTarget", "s",
    property_get, property_set,
    0,
    0),
  SD_BUS_PROPERTY(
    "SyslogIdentifier", "s",
    property_get,
    0,
    SD_BUS_VTABLE_PROPERTY_CONST),
  SD_BUS_VTABLE_END
};

int main(int argc, char **argv) {
  /* The bus should be relinquished before the program terminates. The cleanup
   * attribute allows us to do it nicely and cleanly whenever we exit the
   * block.
   */
  _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;

  object o = {
    .log_level = LOG_INFO,
    .log_target = LOG_TARGET_JOURNAL,
    .syslog_identifier = "example",
  };
  int r;

  /* https://man7.org/linux/man-pages/man3/setlogmask.3.html
   * Programs using syslog() instead of sd_journal can use this API to cut logs
   * emission at the source.
   */
  setlogmask(LOG_UPTO(o.log_level));

  /* Acquire a connection to the bus, letting the library work out the details.
   * https://www.freedesktop.org/software/systemd/man/sd_bus_default.html
   */
  r = sd_bus_default(&bus);
  if (r < 0)
    return log_error(o.log_level, r, "sd_bus_default()");

  /* Publish an interface on the bus, specifying our well-known object access
   * path and public interface name.
   * https://www.freedesktop.org/software/systemd/man/sd_bus_add_object.html
   * https://dbus.freedesktop.org/doc/dbus-tutorial.html
   */
  r = sd_bus_add_object_vtable(bus, NULL,
                               "/org/freedesktop/LogControl1",
                               "org.freedesktop.LogControl1",
                               vtable,
                               &o);
  if (r < 0)
    return log_error(o.log_level, r, "sd_bus_add_object_vtable()");

  /* By default, the service is assigned an ephemeral name. Also add a fixed
   * one, so that clients know whom to call.
   * https://www.freedesktop.org/software/systemd/man/sd_bus_request_name.html
   */
  r = sd_bus_request_name(bus, "org.freedesktop.Example", 0);
  if (r < 0)
    return log_error(o.log_level, r, "sd_bus_request_name()");

  for (;;) {
    /* https://www.freedesktop.org/software/systemd/man/sd_bus_wait.html
     */
    r = sd_bus_wait(bus, UINT64_MAX);
    if (r < 0)
      return log_error(o.log_level, r, "sd_bus_wait()");
    /* https://www.freedesktop.org/software/systemd/man/sd_bus_process.html
     */
    r = sd_bus_process(bus, NULL);
    if (r < 0)
      return log_error(o.log_level, r, "sd_bus_process()");
  }

  /* https://www.freedesktop.org/software/systemd/man/sd_bus_release_name.html
   */
  r = sd_bus_release_name(bus, "org.freedesktop.Example");
  if (r < 0)
    return log_error(o.log_level, r, "sd_bus_release_name()");

  return 0;
}

so what did we just do? ๐Ÿ’… this spins up a simple little server on the bus. it implements the LogControl1 interface by handing over the properties that are required, and it lets you set the ones that are writable. and it logs at whatever log level is currently configured, using sd_journal_print(3). iconic behaviour, honestly.

โš ๏ธ heads up bestie, lowkey important: if you ever port this example to other D-Bus libraries, you might have to add manual client privilege checks yourself. why? because those libraries typically do not default to the restrictive defaults that sd-bus gives you. with sd-bus, unprivileged access to properties is controlled by the SD_BUS_VTABLE_UNPRIVILEGED flag โ€” and that flag is opt-in rather than opt-out. so by default you're locked down, and you have to actively choose to open things up. don't sleep on that. ๐Ÿ˜ญ

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

the extended universe, go read these next:


okay that's a wrap on the whole page, bestie ๐ŸŽ€ you made it, i'm so proud. this was systemd 262.1 dropping the ORG.FREE...OGCONTROL1(5) manual page, so if you're reading a different version somewhere down the line, the vibes may have shifted a lil. go forth and implement LogControl1 like the main character you are. mwah. ๐Ÿ’–โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from
  • arch rolling: systemd 262.1-1 ยท LGPL-2.1-or-later AND CC0-1.0 AND GPL-2.0-or-later AND MIT-0
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms