Skip to content

Commit 2b23ecf

Browse files
committed
rec: remove the possiblility to disable structured logging
1 parent fa40293 commit 2b23ecf

File tree

7 files changed

+64
-15
lines changed

7 files changed

+64
-15
lines changed

pdns/logging.hh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ private:
206206

207207
extern std::shared_ptr<Logging::Logger> g_slog;
208208

209-
// Prefer structured logging?
210-
extern bool g_slogStructured;
209+
// Prefer structured logging? Since 5.1.0, we always do. We keep a const, to allow for step-by-step
210+
// removal of old style logging code (for recursor-only code). Note that code shared with auth still uses
211+
// old-style, so the SLOG calls should remain for shared code.
212+
constexpr bool g_slogStructured = true;
211213

212214
// A helper macro to switch between old-style logging and new-style (structured logging)
213215
// A typical use:

pdns/recursordist/docs/upgrade.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ When upgrading several versions, please read **all** notes applying to the upgra
1010
Changed settings
1111
----------------
1212

13-
For YAML settings only: the type of the :ref:`setting-yaml-incoming.edns_padding_from` and :ref:`setting-yaml-incoming.proxy_protocol_from` has been changed from ``String`` to ``Sequence of Subnet``.
13+
- For YAML settings only: the type of the :ref:`setting-yaml-incoming.edns_padding_from` and :ref:`setting-yaml-incoming.proxy_protocol_from` has been changed from ``String`` to ``Sequence of Subnet``.
14+
15+
- Disabling :ref:`setting-structured-logging` is no longer supported.
16+
17+
Changed Settings
18+
^^^^^^^^^^^^^^^^
1419

1520
5.0.2 to 5.0.3, 4.9.3 to 4.9.4 and 4.8.6 to 4.8.7
1621
-------------------------------------------------

pdns/recursordist/logging.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,3 @@ Logger::~Logger()
156156
};
157157

158158
std::shared_ptr<Logging::Logger> g_slog{nullptr};
159-
bool g_slogStructured = true;

pdns/recursordist/rec-main.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,7 +3082,6 @@ int main(int argc, char** argv)
30823082
// Pick up options given on command line to setup logging asap.
30833083
g_quiet = ::arg().mustDo("quiet");
30843084
s_logUrgency = (Logger::Urgency)::arg().asNum("loglevel");
3085-
g_slogStructured = ::arg().mustDo("structured-logging");
30863085
s_structured_logger_backend = ::arg()["structured-logging-backend"];
30873086

30883087
if (!g_quiet && s_logUrgency < Logger::Info) { // Logger::Info=6, Logger::Debug=7
@@ -3091,8 +3090,8 @@ int main(int argc, char** argv)
30913090
g_log.setLoglevel(s_logUrgency);
30923091
g_log.toConsole(s_logUrgency);
30933092
showProductVersion();
3094-
if (!g_slogStructured) {
3095-
g_log << Logger::Warning << "Disabling structured logging is deprecated, old-style logging wil be removed in a future release" << endl;
3093+
if (!::arg().mustDo("structured-logging")) {
3094+
g_log << Logger::Error << "Disabling structured logging is not supported anymore" << endl;
30963095
}
30973096

30983097
g_yamlSettings = false;
@@ -3182,7 +3181,6 @@ int main(int argc, char** argv)
31823181

31833182
g_quiet = ::arg().mustDo("quiet");
31843183
s_logUrgency = (Logger::Urgency)::arg().asNum("loglevel");
3185-
g_slogStructured = ::arg().mustDo("structured-logging");
31863184

31873185
if (s_logUrgency < Logger::Error) {
31883186
s_logUrgency = Logger::Error;

pdns/recursordist/rec_control.cc

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#endif
2525

2626
#include <iostream>
27+
#include <iomanip>
2728
#include <fcntl.h>
2829

2930
#include "pdnsexception.hh"
@@ -32,14 +33,16 @@
3233
#include "namespaces.hh"
3334
#include "rec_channel.hh"
3435
#include "settings/cxxsettings.hh"
36+
#include "logger.hh"
37+
#include "logging.hh"
3538

3639
ArgvMap& arg()
3740
{
3841
static ArgvMap arg;
3942
return arg;
4043
}
4144

42-
static void initArguments(int argc, char** argv)
45+
static void initArguments(int argc, char** argv, Logr::log_t log)
4346
{
4447
arg().set("config-dir", "Location of configuration directory (recursor.conf)") = SYSCONFDIR;
4548

@@ -81,11 +84,11 @@ static void initArguments(int argc, char** argv)
8184
case pdns::settings::rec::YamlSettingsStatus::CannotOpen:
8285
break;
8386
case pdns::settings::rec::YamlSettingsStatus::PresentButFailed:
84-
cerr << "YAML config found for configname '" << yamlconfigname << "' but error ocurred processing it" << endl;
87+
log->error(Logr::Error, msg, "YAML config found, but error ocurred processing it", "configname", Logging::Loggable(yamlconfigname));
8588
exit(1); // NOLINT(concurrency-mt-unsafe)
8689
break;
8790
case pdns::settings::rec::YamlSettingsStatus::OK:
88-
cout << "YAML config found and processed for configname '" << yamlconfigname << "'" << endl;
91+
log->info(Logr::Notice, "YAML config found and processed", "configname", Logging::Loggable(yamlconfigname));
8992
pdns::settings::rec::bridgeStructToOldStyleSettings(settings);
9093
break;
9194
}
@@ -235,9 +238,51 @@ static RecursorControlChannel::Answer showYAML(const std::string& path)
235238
}
236239
}
237240

241+
static void recControlLoggerBackend(const Logging::Entry& entry)
242+
{
243+
static thread_local std::stringstream buf;
244+
245+
// First map SL priority to syslog's Urgency
246+
Logger::Urgency urg = entry.d_priority != 0 ? Logger::Urgency(entry.d_priority) : Logger::Info;
247+
if (urg > Logger::Warning) {
248+
// We do not log anything if the Urgency of the message is lower than the requested loglevel.
249+
// Not that lower Urgency means higher number.
250+
return;
251+
}
252+
buf.str("");
253+
buf << "msg=" << std::quoted(entry.message);
254+
if (entry.error) {
255+
buf << " error=" << std::quoted(entry.error.get());
256+
}
257+
258+
if (entry.name) {
259+
buf << " subsystem=" << std::quoted(entry.name.get());
260+
}
261+
buf << " level=" << std::quoted(std::to_string(entry.level));
262+
if (entry.d_priority != 0) {
263+
buf << " prio=" << std::quoted(Logr::Logger::toString(entry.d_priority));
264+
}
265+
#if 0
266+
// Thread id filled in by backend, since the SL code does not know about RecursorThreads
267+
// We use the Recursor thread, other threads get id 0. May need to revisit.
268+
buf << " tid=" << std::quoted(std::to_string(RecThreadInfo::id()));
269+
std::array<char, 64> timebuf{};
270+
buf << " ts=" << std::quoted(toTimestampStringMilli(entry.d_timestamp, timebuf));
271+
#endif
272+
for (auto const& value : entry.values) {
273+
buf << " ";
274+
buf << value.first << "=" << std::quoted(value.second);
275+
}
276+
277+
cerr << buf.str() << endl;
278+
}
279+
238280
int main(int argc, char** argv)
239281
{
240-
g_slogStructured = false;
282+
g_slog = Logging::Logger::create(recControlLoggerBackend);
283+
auto log = g_slog->withName("config");
284+
::arg().setSLog(log);
285+
241286
const set<string> fileCommands = {
242287
"dump-cache",
243288
"dump-edns",
@@ -252,7 +297,7 @@ int main(int argc, char** argv)
252297
"trace-regex",
253298
};
254299
try {
255-
initArguments(argc, argv);
300+
initArguments(argc, argv, log);
256301
string sockname = "pdns_recursor";
257302

258303
if (arg()["config-name"] != "")
@@ -355,7 +400,7 @@ int main(int argc, char** argv)
355400
return receive.d_ret;
356401
}
357402
catch (PDNSException& ae) {
358-
cerr << "Fatal: " << ae.reason << "\n";
403+
log->error(Logr::Error, ae.reason, "Fatal");
359404
return 1;
360405
}
361406
}

pdns/recursordist/settings/table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,6 +2657,7 @@
26572657
''',
26582658
'versionadded': '4.6.0',
26592659
'versionchanged': ('5.0.0', 'Disabling structured logging is deprecated'),
2660+
'versionchanged': ('5.1.0', 'Disabling structured logging is not supported'),
26602661
},
26612662
{
26622663
'name' : 'structured_logging_backend',
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
YAML config found and processed for configname './recursor.yml'
21
bye nicely

0 commit comments

Comments
 (0)