diff --git a/doorlockd/CMakeLists.txt b/doorlockd/CMakeLists.txt index 864e85a..5b5d21c 100644 --- a/doorlockd/CMakeLists.txt +++ b/doorlockd/CMakeLists.txt @@ -59,7 +59,7 @@ set(CMAKE_CXX_FLAGS "-O2 -Wall -pedantic -Wextra -Weffc++ -Wno-unused-result") set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb -Wall -pedantic -Wextra -Wno-unused-result") set(CMAKE_C_FLAGS "-O2 -Wall -pedantic -Wextra -Wno-unused-result") -find_package(Boost 1.55.0 COMPONENTS program_options system REQUIRED) +find_package(Boost 1.55.0 COMPONENTS filesystem program_options system REQUIRED) set(JSON_INCLUDE_DIR "/usr/include/jsoncpp" CACHE PATH "path to jsoncpp includes") diff --git a/doorlockd/config.h.in b/doorlockd/config.h.in index 384f007..58b6599 100644 --- a/doorlockd/config.h.in +++ b/doorlockd/config.h.in @@ -23,10 +23,12 @@ #define DEFAULT_LDAP_URI "ldaps://ldap1.binary.kitchen/ ldaps://ldap2.binary.kitchen/ ldaps://ldapm.binary.kitchen/" #define DEFAULT_BINDDN "cn=%s,ou=people,dc=binary-kitchen,dc=de" #define DEFAULT_TOKEN_LENGTH 6 -#define DEFAULT_LOG_FILE "/var/log/doorlockd.log" +#define DEFAULT_LOG_DIR "/var/log/" #define DEFAULT_SERIAL_DEVICE "/dev/ttyAMA0" #define DEFAULT_SERIAL_BAUDRATE 9600UL +#define LOG_FILENAME "doorlockd.log" + #define SHARED_LOCATION "@CMAKE_INSTALL_PREFIX@/share/doorlockd/" #define IMAGE_LOCATION SHARED_LOCATION "images/" diff --git a/doorlockd/daemon/doorlockd.cpp b/doorlockd/daemon/doorlockd.cpp index 5977645..b56b2d9 100644 --- a/doorlockd/daemon/doorlockd.cpp +++ b/doorlockd/daemon/doorlockd.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -12,6 +13,7 @@ namespace po = boost::program_options; namespace ba = boost::asio; +namespace fs = boost::filesystem; using ba::ip::tcp; // Info about doorlockd version @@ -162,6 +164,7 @@ int main(int argc, char** argv) std::string ldapUri; std::string bindDN; std::string lockPagePrefix; + fs::path logdir; std::string logfile; unsigned int tokenLength; std::string serDev; @@ -191,8 +194,8 @@ int main(int argc, char** argv) ("tokenLength,t", po::value(&tokenLength)->default_value(DEFAULT_TOKEN_LENGTH), "Token length") - ("logfile,l", - po::value(&logfile)->default_value(DEFAULT_LOG_FILE), + ("logdir,l", + po::value(&logdir)->default_value(DEFAULT_LOG_DIR), "Log file") ("serial,i", po::value(&serDev)->default_value(DEFAULT_SERIAL_DEVICE), @@ -215,6 +218,8 @@ int main(int argc, char** argv) tokenTimeout = std::chrono::seconds(timeout); + logfile = (logdir / LOG_FILENAME).string(); + l.setLogFile(logfile); l.logFile(true); }