completed first release

This commit is contained in:
Hendrik Schutter 2018-10-17 17:03:07 +02:00
parent 25015beb33
commit 358f5e322b
3 changed files with 178 additions and 36 deletions

View File

@ -15,7 +15,20 @@ int main(void)
//CFTPClient* ftp = new CFTPClient(PRINT_LOG);
Logger* log = new Logger();
struct sID id;
id.description = "CCTV_Radar © CopterSicht 2018";
id.deviceID = "Camera04";
id.softwareID = "0.1.1.8";
id.hardwareID = "7.77.9";
Logger* logging = new Logger("./test.txt", id);
logging->info("Alle Systeme laufen!");
logging->warning("Alle Systeme laufen!");
logging->error("Alle Systeme laufen!");

View File

@ -1,26 +1,125 @@
#include "logger.h"
// 02_Tuesday-16.-October-2018.log
// /logs/2018/09_September/
using namespace std;
Logger::Logger(){
cout << "Construtor" << endl;
logFile.open("testLog.txt", ios_base::app);
string version = "0.1";
Logger::Logger(string pLogPath,struct sID id) {
this->logPath =pLogPath;
writeLog("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
writeLog("+ +");
writeLog("+ Device: " + id.deviceID + " -- " + id.description + " +");
writeLog("+ +");
writeLog("+ Software ID: " + id.softwareID + " -- Build time: " + __DATE__ + " " + __TIME__ + " +");
writeLog("+ +");
writeLog("+ Hardware ID: " + id.hardwareID + " -- MAC: " + getMacAddress() + " +");
writeLog("+ +");
writeLog("+ cppSimpleLogger -- available from https://git.mosad.xyz/localhorst/cppSimpleLogger -- Version: " + version + " +");
writeLog("+ +");
writeLog("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
newLine();
info("Created new log file");
newLine();
}
Logger::~Logger(){
cout << "Destrutor" << endl;
logFile.open("testLog.txt", ios_base::app);
Logger::~Logger() {
}
void Logger::info(string s) {
string tmp = getTimestamp() + " [INFO] " + s;
writeLog(tmp);
}
void Logger::warning(string s) {
string tmp = getTimestamp() + " [WARNING] " + s;
writeLog(tmp);
}
void Logger::error(string s) {
string tmp = getTimestamp() + " [ERROR] " + s;
writeLog(tmp);
}
void Logger::writeLog(string s) {
ofstream logFile;
logFile.open(this->logPath, ios_base::app);
logFile << (s + "\n");
logFile.close();
}
void Logger::newLine() {
writeLog(" ");
}
string Logger::getTimestamp() {
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,80,"%d/%m/%Y %T",timeinfo);
return buffer;
}
string Logger::getMacAddress()
{
struct ifreq ifr;
int s;
if ((s = socket(AF_INET, SOCK_STREAM,0)) < 0) {
//perror("socket");
//return -1;
}
strcpy(ifr.ifr_name, "eth0");
if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
//perror("ioctl");
strcpy(ifr.ifr_name, "eno1");
if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
//perror("ioctl");
//return -1;
}
}
unsigned char *hwaddr = (unsigned char *)ifr.ifr_hwaddr.sa_data;
char buffer [80];
sprintf(buffer,"%02X:%02X:%02X:%02X:%02X:%02X", hwaddr[0], hwaddr[1], hwaddr[2],
hwaddr[3], hwaddr[4], hwaddr[5]);
close(s);
string tmp = buffer;
//cout << tmp << endl;
return tmp;
}

View File

@ -1,29 +1,59 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <net/if.h>
#include <unistd.h>
using namespace std;
struct sID {
string description;
string deviceID;
string softwareID;
string hardwareID;
} ;
class Logger {
private:
ofstream logFile;
writeLog();
getTimestamp();
private:
string logPath;
string getTimestamp();
void writeLog(string s);
string getMacAddress();
public:
Logger();
Logger(string pLogPath, struct sID id);
~Logger();
info(string s);
warning(string s);
error(string s);
void info(string s);
void warning(string s);
void error(string s);
void newLine();
};