From b2a128d2f3ca5b5082c285e1bae10589c27a2204 Mon Sep 17 00:00:00 2001 From: Doug Hoyte Date: Fri, 8 Sep 2023 17:46:55 -0400 Subject: [PATCH] Normally when a plugin blocks an event, it will log a message. Especially when using plugins in `stream`, `router`, etc, this might be too verbose. In order to silence these logs, return an empty string for `msg` (or no `msg` at all). --- docs/plugins.md | 1 + src/apps/mesh/cmd_router.cpp | 4 ++-- src/apps/mesh/cmd_stream.cpp | 2 +- src/apps/mesh/cmd_sync.cpp | 2 +- src/apps/relay/RelayWriter.cpp | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/plugins.md b/docs/plugins.md index 6b480bf..32d8abc 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -77,4 +77,5 @@ To install: * If applicable, you should ensure stdout is *line buffered* (for example, in perl use `$|++`). * If events are being rejected with `error: internal error`, then check the strfry logs. The plugin is misconfigured or failing. +* Normally when a plugin blocks an event, it will log a message. Especially when using plugins in `stream`, `router`, etc, this might be too verbose. In order to silence these logs, return an empty string for `msg` (or no `msg` at all). * When returning an action of `accept`, it doesn't necessarily guarantee that the event will be accepted. The regular strfry checks are still subsequently applied, such as expiration, deletion, etc. diff --git a/src/apps/mesh/cmd_router.cpp b/src/apps/mesh/cmd_router.cpp index 6d87499..45203f3 100644 --- a/src/apps/mesh/cmd_router.cpp +++ b/src/apps/mesh/cmd_router.cpp @@ -187,7 +187,7 @@ struct Router { if (res == PluginEventSifterResult::Accept) { router->writer.write({ std::move(evJson), EventSourceType::Stream, url }); } else { - LI << groupName << " / " << url << " : pluginDown blocked event " << evJson.at("id").get_string() << ": " << okMsg; + if (okMsg.size()) LI << groupName << " / " << url << " : pluginDown blocked event " << evJson.at("id").get_string() << ": " << okMsg; } } @@ -212,7 +212,7 @@ struct Router { if (c.ws) c.ws->send(responseStr.data(), responseStr.size(), uWS::OpCode::TEXT, nullptr, nullptr, true); } } else { - LI << groupName << " : pluginUp blocked event " << evJson.at("id").get_string() << ": " << okMsg; + if (okMsg.size()) LI << groupName << " : pluginUp blocked event " << evJson.at("id").get_string() << ": " << okMsg; } } }; diff --git a/src/apps/mesh/cmd_stream.cpp b/src/apps/mesh/cmd_stream.cpp index f1a3ebf..9d5f11c 100644 --- a/src/apps/mesh/cmd_stream.cpp +++ b/src/apps/mesh/cmd_stream.cpp @@ -72,7 +72,7 @@ void cmd_stream(const std::vector &subArgs) { downloadedIds.emplace(from_hex(evJson.at("id").get_string())); writer.write({ std::move(evJson), EventSourceType::Stream, url }); } else { - LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg; + if (okMsg.size()) LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg; } } else { LW << "Unexpected EVENT"; diff --git a/src/apps/mesh/cmd_sync.cpp b/src/apps/mesh/cmd_sync.cpp index 1dd5c14..9187905 100644 --- a/src/apps/mesh/cmd_sync.cpp +++ b/src/apps/mesh/cmd_sync.cpp @@ -164,7 +164,7 @@ void cmd_sync(const std::vector &subArgs) { if (res == PluginEventSifterResult::Accept) { writer.write({ std::move(evJson), EventSourceType::Sync, url }); } else { - LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg; + if (okMsg.size()) LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg; } } else if (msg.at(0) == "EOSE") { inFlightDown = false; diff --git a/src/apps/relay/RelayWriter.cpp b/src/apps/relay/RelayWriter.cpp index 3460930..e1d95a8 100644 --- a/src/apps/relay/RelayWriter.cpp +++ b/src/apps/relay/RelayWriter.cpp @@ -48,7 +48,7 @@ void RelayServer::runWriter(ThreadPool::Thread &thr) { auto *flat = flatbuffers::GetRoot(msg->flatStr.data()); auto eventIdHex = to_hex(sv(flat->id())); - LI << "[" << msg->connId << "] write policy blocked event " << eventIdHex << ": " << okMsg; + if (okMsg.size()) LI << "[" << msg->connId << "] write policy blocked event " << eventIdHex << ": " << okMsg; sendOKResponse(msg->connId, eventIdHex, res == PluginEventSifterResult::ShadowReject, okMsg); }