A library for logging options
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
log/lib/log.hpp

123 lines
1.9 KiB

1 year ago
#ifndef _LOG_
#define _LOG_
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
1 year ago
#include <fstream>
#include <time.h>
#include <sys/stat.h>
#include <mutex>
1 year ago
#if _WIN32
typedef unsigned int uint;
#endif
namespace marcelb {
6 months ago
namespace logging {
1 year ago
using namespace std;
6 months ago
typedef enum {
DEBUG = 0,
INFO,
WARNING,
ERROR,
FATAL,
} Level;
/**
* Log class - used at the level of one log directory
*/
1 year ago
class log {
string dir;
6 months ago
Level loglevel;
1 year ago
bool isKeepOpen;
bool printInConsole;
1 year ago
ofstream logfile;
struct tm * moment;
uint day;
string path;
mutex io;
1 year ago
/**
* Checking if the path is in the string dir directory
*/
1 year ago
bool isdir();
/**
* Opens the log file
*/
1 year ago
bool open();
/**
* Closes the log file
*/
1 year ago
void loose();
/**
* Get time
*/
1 year ago
void setMoment();
/**
* Generate full log file path
*/
1 year ago
void setPath();
/**
* Set log line time prefix
*/
6 months ago
void setPrefix(string &logline, Level &_level);
/**
* Put string log in file
*/
void put(string logline, Level _level);
1 year ago
public:
/**
* Constructor,
* receives the log directory path,
* optional: a bool variable if it keeps the file open,
* and a bool variable if it prints log lines to the console
*/
6 months ago
log (string _dir, Level loglevel = WARNING, bool _isKeepOpen = true, bool _printInConsole = false);
/**
6 months ago
* Debug log line
*/
void debug(string logline);
/**
* Info log line
*/
void info(string logline);
/**
* Warning log line
*/
void warning(string logline);
/**
* Error log line
*/
void error(string logline);
/**
* Fatal log line
*/
6 months ago
void fatal(string logline);
/**
* Destruktor, close log files
*/
1 year ago
~log();
};
6 months ago
}
}
1 year ago
#endif