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
`${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
# 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.
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
}
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);
}
#include <mutex>
#include <string>
#include <sys/types.h>
+#include <syslog.h>
#include <vector>
using namespace std;
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.
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;
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;
// 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 {