Commit 0d1efe0f authored by Stephen Morris's avatar Stephen Morris
Browse files

[trac558] Fixes after review

Further changes after review.  Also removed some includes of
<iostream> left over from debugging.
parent 7abd3c88
......@@ -391,7 +391,7 @@ writeProgramFile(const string& file, const string& prefix,
" NULL\n" <<
"};\n" <<
"\n" <<
"isc::log::MessageInitializer initializer(values);\n" <<
"const isc::log::MessageInitializer initializer(values);\n" <<
"\n" <<
"} // Anonymous namespace\n" <<
"\n";
......
......@@ -12,8 +12,6 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE
#include <iostream>
#include <stdarg.h>
#include <stdio.h>
......
......@@ -203,7 +203,6 @@ LoggerImpl::output(const char* sev_text, const MessageID& ident,
// Obtain text of the message and substitute arguments.
const string format = MessageDictionary::globalDictionary().getText(ident);
vsnprintf(message, sizeof(message), format.c_str(), ap);
message[sizeof(message) - 1] = '\0'; // Guarantee trailing NULL
// Get the time in a struct tm format, and convert to text
time_t t_time;
......@@ -212,7 +211,6 @@ LoggerImpl::output(const char* sev_text, const MessageID& ident,
char chr_time[32];
(void) strftime(chr_time, sizeof(chr_time), "%Y-%m-%d %H:%M:%S", tm_time);
chr_time[sizeof(chr_time) - 1] = '\0'; // Guarantee a trailing NULL
// Now output.
std::cout << chr_time << " " << sev_text << " [" << getName() << "] " <<
......
......@@ -19,7 +19,6 @@
#include <time.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <map>
#include <utility>
......
......@@ -94,7 +94,7 @@ readLocalMessageFile(const char* file) {
/// Logger Run-Time Initialization
void
init(const string& root, isc::log::Severity severity, int dbglevel,
initLogger(const string& root, isc::log::Severity severity, int dbglevel,
const char* file) {
// Create the application root logger and set the default severity and
......
......@@ -36,8 +36,8 @@ namespace log {
/// \param severity Severity at which to log
/// \param dbglevel Debug severiy (ignored if "severity" is not "DEBUG")
/// \param file Name of the local message file.
void init(const std::string& root, isc::log::Severity severity, int dbglevel,
const char* file);
void initLogger(const std::string& root, isc::log::Severity severity,
int dbglevel, const char* file);
} // namespace log
} // namespace isc
......
......@@ -12,8 +12,6 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <iostream>
#include <cstddef>
#include <log/message_dictionary.h>
#include <log/message_types.h>
......
......@@ -15,7 +15,6 @@
#ifndef __MESSAGE_READER_H
#define __MESSAGE_READER_H
#include <iostream>
#include <map>
#include <string>
#include <vector>
......
// File created from messagedef.mes on Wed Feb 9 16:55:11 2011
// File created from messagedef.mes on Mon Feb 14 11:07:45 2011
#include <cstddef>
#include <log/message_types.h>
......@@ -51,7 +51,7 @@ const char* values[] = {
NULL
};
isc::log::MessageInitializer initializer(values);
const isc::log::MessageInitializer initializer(values);
} // Anonymous namespace
// File created from messagedef.mes on Wed Feb 9 16:55:11 2011
// File created from messagedef.mes on Mon Feb 14 11:07:45 2011
#ifndef __MESSAGEDEF_H
#define __MESSAGEDEF_H
......
......@@ -18,17 +18,27 @@
namespace isc {
namespace log {
static std::string root_name_;
namespace {
// Obtain the root logger name in a way that is safe for statically-initialized
// objects.
std::string&
getRootLoggerNameInternal() {
static std::string root_name;
return (root_name);
}
} // Anonymous namespace
void
setRootLoggerName(const std::string& name) {
root_name_ = name;
getRootLoggerNameInternal() = name;
}
const std::string& getRootLoggerName() {
return root_name_;
return getRootLoggerNameInternal();
}
}
}
} // namespace log
} // namespace isc
......@@ -19,20 +19,25 @@
/// \brief Define Name of Root Logger
///
/// In the log4cxx system, the root logger is ".". The definition for the
/// BIND-10 system is that the root logger of a program has the name of the
/// program. This (trivial) class stores the name of the program in a
/// location accessible to the logger classes.
/// IN BIND-10, the name root logger of a program is the name of the program
/// itself (in contrast to packages such as log4cxx where the root logger name
// is something like "."). These trivial functions allow the setting and
// getting of that name by the logger classes.
namespace isc {
namespace log {
/// \brief Set Root Logger Name
///
/// \param name Name of the root logger. This should be the program
/// name.
/// This function should be called by the program's initialization code before
/// any logging functions are called.
///
/// \param name Name of the root logger. This should be the program name.
void setRootLoggerName(const std::string& name);
/// \brief Get Root Logger Name
///
/// \return Name of the root logger.
const std::string& getRootLoggerName();
}
......
......@@ -13,7 +13,6 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <numeric>
#include <iostream>
#include <string.h>
#include <strutil.h>
......
......@@ -31,9 +31,8 @@
using namespace isc::log;
// Declare root logger and a loggers to use an example.
// Declare logger to use an example.
Logger logger_ex("example");
Logger logger_dlm("dlm");
// The program is invoked:
//
......@@ -48,10 +47,11 @@ Logger logger_dlm("dlm");
int main(int argc, char** argv) {
isc::log::Severity severity = isc::log::INFO;
int dbglevel = -1;
const char* localfile = NULL;
int option;
isc::log::Severity severity = isc::log::INFO; // Default logger severity
int dbglevel = -1; // Logger debug level
const char* localfile = NULL; // Local message file
int option; // For getopt() processing
Logger logger_dlm("dlm", true); // Another example logger
// Parse options
while ((option = getopt(argc, argv, "s:d:")) != -1) {
......@@ -89,7 +89,7 @@ int main(int argc, char** argv) {
}
// Update the logging parameters
init("alpha", severity, dbglevel, localfile);
initLogger("alpha", severity, dbglevel, localfile);
// Log a few messages
logger_ex.fatal(MSG_MSGWRTERR, "test1", "42");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment