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

86 lines
1.3 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 {
1 year ago
using namespace std;
/**
* Log class - used at the level of one log directory
*/
1 year ago
class log {
string dir;
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
*/
1 year ago
void setPrefix(string &logline);
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
*/
log (string _dir, bool _isKeepOpen = true, bool _printInConsole = false);
/**
* Put string log in file
*/
void put(string logline);
/**
* Destruktor, close log files
*/
1 year ago
~log();
};
}
1 year ago
#endif