added log functionality

pull/23/head
JuanJakobo 2020-08-05 21:10:48 +02:00
parent 05e5dd213f
commit aa77c53ebf
6 changed files with 73 additions and 4 deletions

View File

@ -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
)

View File

@ -13,6 +13,8 @@
#include "nextcloud.h"
#include "listView.h"
const string CONFIG_PATH = "/mnt/ext1/system/config/nextcloud";
class EventHandler
{
public:

30
src/util/log.cpp 100644
View File

@ -0,0 +1,30 @@
//------------------------------------------------------------------
// log.cpp
//
// Author: JuanJakobo
// Date: 04.08.2020
//
//-------------------------------------------------------------------
#include "log.h"
#include "eventHandler.h"
#include <string>
#include <fstream>
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";
}

33
src/util/log.h 100644
View File

@ -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 <string>
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

View File

@ -9,7 +9,6 @@
#include "inkview.h"
#include <string>
#include <math.h>
#include <sstream>
string Util::intToString(int value)

View File

@ -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 <string>
@ -40,3 +43,4 @@ public:
private:
Util() {}
};
#endif