]> git.hungrycats.org Git - bees/commitdiff
reporter: add a log sink for reports (filename = -)
authorZygo Blaxell <bees@furryterror.org>
Wed, 17 Jun 2026 04:57:03 +0000 (00:57 -0400)
committerZygo Blaxell <bees@furryterror.org>
Tue, 6 Oct 2026 05:51:40 +0000 (01:51 -0400)
Reports could only be written to files.  Folding the legacy progress log into
the reporter needs a report that emits to the log instead, so the periodic
counter/thread output keeps appearing where operators watch it.

A report whose filename is "-" is a log sink: write_report renders its tokens
as usual, then emits the result via BEESLOG at the report's level rather than
writing a file.  Add a per-report "level" key (syslog-style integer, default
LOG_INFO) and resolve "-" reports to no directory fd.  BEESLOG applies the
same category-level gate as every other log call, so a "-" report respects
log verbosity like anything else.

Assisted-by: Claude-Code:claude-opus-4-8
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
docs/config-file.md
src/bees-config-v1.cc
src/bees-reporter.cc
src/bees-reporter.h
src/bees.cc

index f0b0ec6e5a57e69243ede5690092b92c48445e17..1ff3fc5113c4cbe55ea89f9e1e5d5b14818435f6 100644 (file)
@@ -342,6 +342,10 @@ not empty.
   restrictive because they can expose target filesystem paths.  Aggregate-only
   reports can use wider modes for monitoring agents.
 
+* **`level`**
+  syslog-style level (`0`=EMERG … `6`=INFO, `7`=DEBUG) used when the report is
+  emitted to the log (`filename = -`).  Ignored for file reports.  Default: `6`.
+
 * **`user`**
   Owner for the report file.  Accepts a user name or numeric uid.
   An all-digits string is treated as a numeric uid; any other string is
@@ -364,6 +368,9 @@ not empty.
   `${BASENAME}` are expanded.  Empty disables this report even when
   `active = yes`.  Default: empty.
 
+  A filename of `-` emits the report to the log at `level` instead of writing
+  a file (no directory is resolved).
+
   If the filename begins with `/`, the file is written relative to the
   mount namespace root (`/`) when bees starts up, before any mount
   namespace change inside the bees process; otherwise, the file is
index 993dce0475aba79e604648f8946c11886a3104c1..88d90197df43e3a0ec63afdd3c04b8e173ffe81d 100644 (file)
@@ -142,6 +142,10 @@ static const char bees_config_v1[] = R"--v1-config--(
         # temporary file and renamed into place atomically.
         mode = 0400
 
+        # syslog-style level (0=EMERG ... 6=INFO, 7=DEBUG) used when the report
+        # is emitted to the log (filename = -).  Ignored for file reports.
+        level = 6
+
         # Owner of the report file.  Accepts a name or numeric uid.
         # Resolved to a uid once at startup; an unknown name is a config error.
         # Empty = no chown; file is owned by the bees process user.
@@ -153,6 +157,8 @@ static const char bees_config_v1[] = R"--v1-config--(
         group =
 
         # Filename of the report file.
+        # A filename of '-' emits the report to the log (at the level above)
+        # instead of writing a file.
         # Substitution variables are expanded (${UUID}, ${LABEL}, ${BASENAME}).
         # If the filename begins with '/', all leading slashes are stripped and
         # it is resolved via openat(2) against the filesystem root ('/') opened
index 480d2b21ddb41c61e8e5a128b57ccea8d910e5b6..46a0f9dbd084e409d4eee9b719f3cd39e88cb69e 100644 (file)
@@ -132,6 +132,14 @@ BeesReporter::write_report(const BeesReportConfig &cfg)
        }
        const auto content = oss.str();
 
+       // A filename of "-" is a log sink, not a file: emit at the configured
+       // level instead of writing.  BEESLOG applies the same category-level
+       // gate as every other log call.
+       if (cfg.filename == "-") {
+               BEESLOG(cfg.log_level, content);
+               return;
+       }
+
        write_atomic(cfg.dir_fd, cfg.rel_filename, content, cfg.mode, cfg.uid, cfg.gid);
 }
 
index c1d7c02f0f8a1dfd4a40d7c641768f8326e7c0f7..b59d7366adebdcb5bcfa23b548d329a918b46b2e 100644 (file)
@@ -8,6 +8,7 @@
 #include <mutex>
 #include <string>
 #include <sys/types.h>
+#include <syslog.h>
 #include <vector>
 
 using namespace std;
@@ -18,7 +19,8 @@ struct BeesReportConfig {
        string               name;                   ///< Section name (e.g. "legacy").
        bool                 active      = false;    ///< Whether this output is written.
        double               interval_s  = 1.0;      ///< Target rewrite interval (seconds).
-       string               filename;               ///< Report filename as configured (before path resolution).
+       string               filename;               ///< Report filename as configured (before path resolution).  "-" means emit to the log.
+       int                  log_level   = LOG_INFO;  ///< syslog level used when filename is "-".
        mode_t               mode        = 0400;     ///< fchmod value applied before rename.
        uid_t                uid         = uid_t(-1); ///< fchown uid; -1 = no chown.
        gid_t                gid         = gid_t(-1); ///< fchown gid; -1 = no chown.
index c7dae7328d45ac47b30f3f93061ebb2b77e1fac7..5083172d13014ab950b1b05041b4e55c86529ac8 100644 (file)
@@ -408,9 +408,16 @@ bees_main(int argc, char *argv[])
                        cfg.mode = bc->get_config().get_trusted(prefix + "mode", [](const string &s) {
                                return mode_t(stoul(s, nullptr, 8));
                        });
+                       cfg.log_level = bc->get_config().get(prefix + "level", [](const string &s) {
+                               return stoi(s);
+                       });
                        if (cfg.active) {
                                BEESLOGINFO("report." << sec_name << ".interval = " << cfg.interval_s << "s"
                                        << " [report." << sec_name << ".interval]");
+                               if (cfg.filename == "-") {
+                                       BEESLOGINFO("report." << sec_name << ".level = " << cfg.log_level
+                                               << " [report." << sec_name << ".level]");
+                               }
                                BEESLOGINFO("report." << sec_name << ".filename = '" << cfg.filename << "'"
                                        << " [report." << sec_name << ".filename]");
                                ostringstream mode_oss;
@@ -487,7 +494,9 @@ bees_main(int argc, char *argv[])
                bool needs_mount_root = false;
                for (const auto &cfg : configs) {
                        if (!cfg.active || cfg.filename.empty()) continue;
-                       if (cfg.filename.at(0) == '/') {
+                       if (cfg.filename == "-") {
+                               // Log sink: emitted via BEESLOG, needs no directory fd.
+                       } else if (cfg.filename.at(0) == '/') {
                                needs_mount_root = true;
                        } else {
                                needs_reports_path = true;
@@ -528,7 +537,10 @@ bees_main(int argc, char *argv[])
                // Resolve (dir_fd, rel_filename) for each active report before adding
                for (auto &cfg : configs) {
                        if (cfg.active && !cfg.filename.empty()) {
-                               if (cfg.filename.at(0) == '/') {
+                               if (cfg.filename == "-") {
+                                       // Log sink: no path resolution; write_report emits via
+                                       // BEESLOG at cfg.log_level.
+                               } else if (cfg.filename.at(0) == '/') {
                                        cfg.dir_fd = mount_root_fd;
                                        cfg.rel_filename = cfg.filename.substr(cfg.filename.find_first_not_of('/'));
                                } else {