From cb78c19f5310ddbb7b01a9847af3a745ea64ec67 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 31 Mar 2025 20:51:36 +0300 Subject: [PATCH] [#3569] added comment and unit test for long logger name --- src/hooks/dhcp/forensic_log/legal_syslog.cc | 7 +++++++ src/lib/log/logger.h | 2 ++ src/lib/log/logger_impl.h | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/src/hooks/dhcp/forensic_log/legal_syslog.cc b/src/hooks/dhcp/forensic_log/legal_syslog.cc index 85d80db478..c6e5ce7057 100644 --- a/src/hooks/dhcp/forensic_log/legal_syslog.cc +++ b/src/hooks/dhcp/forensic_log/legal_syslog.cc @@ -29,6 +29,13 @@ LegalSyslog::LegalSyslog(const DatabaseConnection::ParameterMap& parameters) LoggingInfo info; // Remove default destinations as we are going to replace them. info.clearDestinations(); + /// The name of the logger may be no longer than MAX_LOGGER_NAME_SIZE + /// else the program will throw an exception. This restriction allows + /// loggers to be declared statically: the name is stored in a fixed-size + /// array to avoid the need to allocate heap storage during program + /// initialization (which causes problems on some operating systems). + /// e.g. or error: '' is not a valid name for a logger: + /// valid names must be between 1 and 31 characters in length. info.name_ = "legal-log-"; info.name_ += boost::lexical_cast(reinterpret_cast(this)); logger_.reset(new Logger(info.name_.c_str())); diff --git a/src/lib/log/logger.h b/src/lib/log/logger.h index 78a82ff91b..4178289d8f 100644 --- a/src/lib/log/logger.h +++ b/src/lib/log/logger.h @@ -157,6 +157,8 @@ public: /// loggers to be declared statically: the name is stored in a fixed-size /// array to avoid the need to allocate heap storage during program /// initialization (which causes problems on some operating systems). + /// e.g. or error: '' is not a valid name for a logger: + /// valid names must be between 1 and 31 characters in length. /// /// \note Note also that there is no constructor taking a std::string. This /// minimizes the possibility of initializing a static logger with a diff --git a/src/lib/log/logger_impl.h b/src/lib/log/logger_impl.h index d7dad452ae..f275c9b4f5 100644 --- a/src/lib/log/logger_impl.h +++ b/src/lib/log/logger_impl.h @@ -63,6 +63,14 @@ public: /// /// Creates a logger of the specific name. /// + /// \note The name of the logger may be no longer than MAX_LOGGER_NAME_SIZE + /// else the program will throw an exception. This restriction allows + /// loggers to be declared statically: the name is stored in a fixed-size + /// array to avoid the need to allocate heap storage during program + /// initialization (which causes problems on some operating systems). + /// e.g. or error: '' is not a valid name for a logger: + /// valid names must be between 1 and 31 characters in length. + /// /// \param name Name of the logger. LoggerImpl(const std::string& name);