diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bd2b15..12e0370 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp ${CMAKE_SOURCE_DIR}/src/ui/listView.cpp ${CMAKE_SOURCE_DIR}/src/ui/listViewEntry.cpp ${CMAKE_SOURCE_DIR}/src/util/util.cpp + ${CMAKE_SOURCE_DIR}/src/util/log.cpp ) diff --git a/src/handler/eventHandler.h b/src/handler/eventHandler.h index 37a58c4..c7dff4b 100644 --- a/src/handler/eventHandler.h +++ b/src/handler/eventHandler.h @@ -13,6 +13,8 @@ #include "nextcloud.h" #include "listView.h" +const string CONFIG_PATH = "/mnt/ext1/system/config/nextcloud"; + class EventHandler { public: diff --git a/src/util/log.cpp b/src/util/log.cpp new file mode 100644 index 0000000..b26ee11 --- /dev/null +++ b/src/util/log.cpp @@ -0,0 +1,30 @@ +//------------------------------------------------------------------ +// log.cpp +// +// Author: JuanJakobo +// Date: 04.08.2020 +// +//------------------------------------------------------------------- + +#include "log.h" +#include "eventHandler.h" + +#include +#include + +void Log::writeLog(const string& text) +{ + std::ofstream log(CONFIG_PATH + std::string("/logfile.txt"), std::ios_base::app | std::ios_base::out); + + time_t rawtime; + struct tm * timeinfo; + char buffer[80]; + + time (&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer,sizeof(buffer),"%d/%b/%Y:%H:%M:%S %z",timeinfo); + + log << buffer << ":" << text << "\n"; + +} \ No newline at end of file diff --git a/src/util/log.h b/src/util/log.h new file mode 100644 index 0000000..aba952d --- /dev/null +++ b/src/util/log.h @@ -0,0 +1,33 @@ +//------------------------------------------------------------------ +// log.h +// +// Author: JuanJakobo +// Date: 05.08.2020 +// Description: Deals with log entries +//------------------------------------------------------------------- + +#ifndef LOG +#define LOG + +#include "inkview.h" + +#include + +using namespace std; + + +class Log +{ + public: + + /** + * Writes a log entry to the log file + * + * @param text that shall be written to the log + */ + static void writeLog(const string& text); + + private: + Log() {} +}; +#endif \ No newline at end of file diff --git a/src/util/util.cpp b/src/util/util.cpp index d5b757c..6b9870a 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -9,7 +9,6 @@ #include "inkview.h" #include -#include #include string Util::intToString(int value) diff --git a/src/util/util.h b/src/util/util.h index 224cc3c..edeb86a 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -1,11 +1,14 @@ //------------------------------------------------------------------ -// util.cpp +// util.h // // Author: JuanJakobo // Date: 04.08.2020 -// +// Description: Various utility methods //------------------------------------------------------------------- +#ifndef UTIL +#define UTIL + #include "inkview.h" #include @@ -39,4 +42,5 @@ public: private: Util() {} -}; \ No newline at end of file +}; +#endif \ No newline at end of file