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

82 lines
1.3 KiB

#ifndef _LOG_
#define _LOG_
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <time.h>
#include <sys/stat.h>
#include <mutex>
namespace marcelb {
using namespace std;
/**
* Log class - used at the level of one log directory
*/
class log {
string dir;
bool isKeepOpen;
bool printInConsole;
ofstream logfile;
struct tm * moment;
uint day;
string path;
mutex io;
/**
* Checking if the path is in the string dir directory
*/
bool isdir();
/**
* Opens the log file
*/
bool open();
/**
* Closes the log file
*/
void loose();
/**
* Get time
*/
void setMoment();
/**
* Generate full log file path
*/
void setPath();
/**
* Set log line time prefix
*/
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
*/
~log();
};
}
#endif