Commit 106ec83c authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[1704] Use LoggerImpl as a testcase for InterprocessSync

parent cd6a1513
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <algorithm> #include <algorithm>
#include <memory>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
// namespace: instead, all log4cplus types are explicitly qualified. // namespace: instead, all log4cplus types are explicitly qualified.
using namespace std; using namespace std;
using namespace isc::util;
namespace isc { namespace isc {
namespace log { namespace log {
...@@ -50,11 +52,13 @@ namespace log { ...@@ -50,11 +52,13 @@ namespace log {
LoggerImpl::LoggerImpl(const string& name) : name_(expandLoggerName(name)), LoggerImpl::LoggerImpl(const string& name) : name_(expandLoggerName(name)),
logger_(log4cplus::Logger::getInstance(name_)) logger_(log4cplus::Logger::getInstance(name_))
{ {
sync_ = new InterprocessSyncFile("logger");
} }
// Destructor. (Here because of virtual declaration.) // Destructor. (Here because of virtual declaration.)
LoggerImpl::~LoggerImpl() { LoggerImpl::~LoggerImpl() {
delete sync_;
} }
// Set the severity for logging. // Set the severity for logging.
...@@ -104,6 +108,15 @@ LoggerImpl::lookupMessage(const MessageID& ident) { ...@@ -104,6 +108,15 @@ LoggerImpl::lookupMessage(const MessageID& ident) {
void void
LoggerImpl::outputRaw(const Severity& severity, const string& message) { LoggerImpl::outputRaw(const Severity& severity, const string& message) {
// Use a lock file for mutual exclusion from other processes to
// avoid log messages getting interspersed
auto_ptr<InterprocessSyncLocker> locker(sync_->getLocker());
if (!locker->lock()) {
LOG4CPLUS_ERROR(logger_, "Unable to lock logger lockfile");
}
switch (severity) { switch (severity) {
case DEBUG: case DEBUG:
LOG4CPLUS_DEBUG(logger_, message); LOG4CPLUS_DEBUG(logger_, message);
...@@ -124,6 +137,10 @@ LoggerImpl::outputRaw(const Severity& severity, const string& message) { ...@@ -124,6 +137,10 @@ LoggerImpl::outputRaw(const Severity& severity, const string& message) {
case FATAL: case FATAL:
LOG4CPLUS_FATAL(logger_, message); LOG4CPLUS_FATAL(logger_, message);
} }
if (!locker->unlock()) {
LOG4CPLUS_ERROR(logger_, "Unable to unlock logger lockfile");
}
} }
} // namespace log } // namespace log
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <log/logger_level_impl.h> #include <log/logger_level_impl.h>
#include <log/message_types.h> #include <log/message_types.h>
#include <util/interprocess_sync_file.h>
namespace isc { namespace isc {
namespace log { namespace log {
...@@ -178,8 +180,9 @@ public: ...@@ -178,8 +180,9 @@ public:
} }
private: private:
std::string name_; ///< Full name of this logger std::string name_; ///< Full name of this logger
log4cplus::Logger logger_; ///< Underlying log4cplus logger log4cplus::Logger logger_; ///< Underlying log4cplus logger
isc::util::InterprocessSync* sync_;
}; };
} // namespace log } // namespace log
......
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