Commit b48f565f authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[3591] Logging variables simplified

 - KEA_LOCKFILE_DIR_FROM_BUILD renamed to KEA_LOCKFILE_DIR.
 - KEA_FROM_BUILD_LOCALSTATEDIR, KEA_LOCKFILE_DIR_FROM_BUILD removed
 - It is possible to disable lockfile now
parent c24182c2
......@@ -96,7 +96,7 @@ void Daemon::configureLogger(const isc::data::ConstElementPtr& log_config,
void Daemon::loggerInit(const char*, bool verbose) {
setenv("KEA_LOCKFILE_DIR_FROM_BUILD", "/tmp", 0);
setenv("KEA_LOCKFILE_DIR", "/tmp", 0);
// Initialize logger system
isc::log::initLogger(isc::log::getDefaultRootLoggerName().c_str(),
......
......@@ -46,21 +46,11 @@ InterprocessSyncFile::do_lock(int cmd, short l_type) {
if (fd_ == -1) {
std::string lockfile_path = LOCKFILE_DIR;
const char* const env = getenv("KEA_FROM_BUILD");
const char* const env = getenv("KEA_LOCKFILE_DIR");
if (env != NULL) {
lockfile_path = env;
}
const char* const env2 = getenv("KEA_FROM_BUILD_LOCALSTATEDIR");
if (env2 != NULL) {
lockfile_path = env2;
}
const char* const env3 = getenv("KEA_LOCKFILE_DIR_FROM_BUILD");
if (env3 != NULL) {
lockfile_path = env3;
}
lockfile_path += "/" + task_name_ + "_lockfile";
// Open the lockfile in the constructor so it doesn't do the access
......
......@@ -20,6 +20,6 @@ int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
setenv("KEA_LOCKFILE_DIR_FROM_BUILD", TEST_DATA_TOPBUILDDIR, 1);
setenv("KEA_LOCKFILE_DIR", TEST_DATA_TOPBUILDDIR, 1);
return (isc::util::unittests::run_all());
}
......@@ -18,8 +18,10 @@
#include <stdarg.h>
#include <stdio.h>
#include <cstring>
#include <boost/lexical_cast.hpp>
#include <boost/static_assert.hpp>
#include <boost/algorithm/string.hpp>
#include <log4cplus/configurator.h>
#include <log4cplus/loggingmacros.h>
......@@ -33,6 +35,7 @@
#include <log/message_dictionary.h>
#include <log/message_types.h>
#include <log/interprocess/interprocess_sync_file.h>
#include <log/interprocess/interprocess_sync_null.h>
#include <util/strutil.h>
......@@ -45,6 +48,20 @@ using namespace std;
namespace isc {
namespace log {
/// @brief detects whether file locking is enabled or disabled
///
/// The lockfile is enabled by default. The only way to disable it is to
/// set KEA_LOCKFILE_DIR variable to 'none'.
/// @return true if lockfile is enabled, false otherwise
bool lockfileEnabled() {
const char* const env = getenv("KEA_LOCKFILE_DIR");
if (env && boost::iequals(string(env), string("none"))) {
return (false);
}
return (true);
}
// Constructor. The setting of logger_ must be done when the variable is
// constructed (instead of being left to the body of the function); at least
// one compiler requires that all member variables be constructed before the
......@@ -52,9 +69,13 @@ namespace log {
// default constructor.
LoggerImpl::LoggerImpl(const string& name) :
name_(expandLoggerName(name)),
logger_(log4cplus::Logger::getInstance(name_)),
sync_(new interprocess::InterprocessSyncFile("logger"))
logger_(log4cplus::Logger::getInstance(name_))
{
if (lockfileEnabled()) {
sync_ = new interprocess::InterprocessSyncFile("logger");
} else {
sync_ = new interprocess::InterprocessSyncNull("logger");
}
}
// Destructor. (Here because of virtual declaration.)
......
......@@ -162,7 +162,7 @@ void initLogger(isc::log::Severity severity, int dbglevel) {
const char* localfile = getenv("KEA_LOGGER_LOCALMSG");
// Set a directory for creating lockfiles when running tests
setenv("KEA_LOCKFILE_DIR_FROM_BUILD", TOP_BUILDDIR, 0);
setenv("KEA_LOCKFILE_DIR", TOP_BUILDDIR, 0);
// Initialize logging
initLogger(root, isc::log::DEBUG, isc::log::MAX_DEBUG_LEVEL, localfile);
......
......@@ -20,6 +20,6 @@ int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
setenv("KEA_LOCKFILE_DIR_FROM_BUILD", TEST_DATA_TOPBUILDDIR, 1);
setenv("KEA_LOCKFILE_DIR", TEST_DATA_TOPBUILDDIR, 1);
return (isc::util::unittests::run_all());
}
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