Skip to content

Commit cb78c19

Browse files
author
Razvan Becheriu
committed
[#3569] added comment and unit test for long logger name
1 parent 9ee776a commit cb78c19

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/hooks/dhcp/forensic_log/legal_syslog.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ LegalSyslog::LegalSyslog(const DatabaseConnection::ParameterMap& parameters)
2929
LoggingInfo info;
3030
// Remove default destinations as we are going to replace them.
3131
info.clearDestinations();
32+
/// The name of the logger may be no longer than MAX_LOGGER_NAME_SIZE
33+
/// else the program will throw an exception. This restriction allows
34+
/// loggers to be declared statically: the name is stored in a fixed-size
35+
/// array to avoid the need to allocate heap storage during program
36+
/// initialization (which causes problems on some operating systems).
37+
/// e.g. or error: '<logger-name>' is not a valid name for a logger:
38+
/// valid names must be between 1 and 31 characters in length.
3239
info.name_ = "legal-log-";
3340
info.name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
3441
logger_.reset(new Logger(info.name_.c_str()));

src/lib/log/logger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Logger {
157157
/// loggers to be declared statically: the name is stored in a fixed-size
158158
/// array to avoid the need to allocate heap storage during program
159159
/// initialization (which causes problems on some operating systems).
160+
/// e.g. or error: '<logger-name>' is not a valid name for a logger:
161+
/// valid names must be between 1 and 31 characters in length.
160162
///
161163
/// \note Note also that there is no constructor taking a std::string. This
162164
/// minimizes the possibility of initializing a static logger with a

src/lib/log/logger_impl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ class LoggerImpl : public boost::noncopyable {
6363
///
6464
/// Creates a logger of the specific name.
6565
///
66+
/// \note The name of the logger may be no longer than MAX_LOGGER_NAME_SIZE
67+
/// else the program will throw an exception. This restriction allows
68+
/// loggers to be declared statically: the name is stored in a fixed-size
69+
/// array to avoid the need to allocate heap storage during program
70+
/// initialization (which causes problems on some operating systems).
71+
/// e.g. or error: '<logger-name>' is not a valid name for a logger:
72+
/// valid names must be between 1 and 31 characters in length.
73+
///
6674
/// \param name Name of the logger.
6775
LoggerImpl(const std::string& name);
6876

0 commit comments

Comments
 (0)