#include <iostream>
#include <iomanip>
#include <algorithm>
+#include <memory>
#include <stdarg.h>
#include <stdio.h>
// namespace: instead, all log4cplus types are explicitly qualified.
using namespace std;
+using namespace isc::util;
namespace isc {
namespace log {
LoggerImpl::LoggerImpl(const string& name) : name_(expandLoggerName(name)),
logger_(log4cplus::Logger::getInstance(name_))
{
+ sync_ = new InterprocessSyncFile("logger");
}
// Destructor. (Here because of virtual declaration.)
LoggerImpl::~LoggerImpl() {
+ delete sync_;
}
// Set the severity for logging.
void
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) {
case DEBUG:
LOG4CPLUS_DEBUG(logger_, message);
case FATAL:
LOG4CPLUS_FATAL(logger_, message);
}
+
+ if (!locker->unlock()) {
+ LOG4CPLUS_ERROR(logger_, "Unable to unlock logger lockfile");
+ }
}
} // namespace log
#include <log/logger_level_impl.h>
#include <log/message_types.h>
+#include <util/interprocess_sync_file.h>
+
namespace isc {
namespace log {
}
private:
- std::string name_; ///< Full name of this logger
- log4cplus::Logger logger_; ///< Underlying log4cplus logger
+ std::string name_; ///< Full name of this logger
+ log4cplus::Logger logger_; ///< Underlying log4cplus logger
+ isc::util::InterprocessSync* sync_;
};
} // namespace log