cppSimpleLogger/logger.h

80 lines
1.6 KiB
C
Raw Permalink Normal View History

2020-09-04 23:57:32 +02:00
/**
* @file logger.h
* @brief cppSimpleLogger Header
* @author hendrik schutter
* @date 04.09.2020
*/
2020-09-07 15:31:09 +02:00
#ifndef LOGGER_H_
#define LOGGER_H_
2018-10-16 23:34:45 +02:00
#include <time.h>
#include <string.h>
#include <iostream>
2018-10-17 17:03:07 +02:00
#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>
2020-09-04 23:57:32 +02:00
#include <sys/time.h>
#include <math.h>
#include <mutex>
2018-10-17 17:03:07 +02:00
using namespace std;
2020-09-04 23:57:32 +02:00
#define MENU_LINE_SIZE 110 //Size of menu lines
2018-10-17 17:03:07 +02:00
2020-09-07 15:31:09 +02:00
#ifndef LOG_PATH
#define LOG_PATH "./test.txt"
#endif
#ifndef DESCRIPTION
#define DESCRIPTION "Software-Name - Copyright Company 2020" //use your values here
#endif
#ifndef DEVICE_ID
#define DEVICE_ID "Device-Name" //use your values here
#endif
#ifndef SOFTWARE_VERSION
#define SOFTWARE_VERSION "0.1.1.8" //use your values here
#endif
#ifndef HARDWARE_VERSION
#define HARDWARE_VERSION "7.77.9" //use your values here
#endif
2018-10-17 17:03:07 +02:00
2020-09-04 23:57:32 +02:00
class Logger
{
2018-10-17 17:03:07 +02:00
private:
string logPath;
2020-09-04 23:57:32 +02:00
mutex mtxLog;
2020-09-07 15:31:09 +02:00
static bool instanceFlag;
static Logger *single;
2018-10-17 17:03:07 +02:00
string getTimestamp();
void writeLog(string s);
string getMacAddress();
2020-09-04 23:57:32 +02:00
string padStringMenu(char cBorder, string text, uint8_t u8LineLenght);
string menuLine(char cBorder, uint8_t u8LineLenght);
2020-09-07 15:31:09 +02:00
Logger();
~Logger();
2018-10-17 17:03:07 +02:00
2018-10-16 23:34:45 +02:00
public:
2020-09-07 15:31:09 +02:00
2018-10-17 17:03:07 +02:00
void info(string s);
void warning(string s);
void error(string s);
void newLine();
2018-10-16 23:34:45 +02:00
2020-09-07 15:31:09 +02:00
static Logger* logThis();
};
2018-10-16 23:34:45 +02:00
2020-09-07 15:31:09 +02:00
#endif // LOGGER_H_