Add semaphore for work wit multithread

testing
marcelb 1 year ago
parent 152c8b6719
commit c2a5995e7e
  1. 3
      .vscode/settings.json
  2. 3
      example/2023-07-27.log
  3. 2
      lib/log.hpp
  4. 2
      src/log.cpp

@ -4,6 +4,7 @@
"iosfwd": "cpp",
"fstream": "cpp",
"*.tcc": "cpp",
"ostream": "cpp"
"ostream": "cpp",
"mutex": "cpp"
}
}

@ -0,0 +1,3 @@
18:29:30 [EVENT] Start loging
18:29:44 [EVENT] Start loging
18:29:47 [EVENT] Start loging

@ -7,6 +7,7 @@
#include <fstream>
#include <time.h>
#include <sys/stat.h>
#include <mutex>
using namespace std;
@ -19,6 +20,7 @@ class log {
struct tm * moment;
uint day;
string path;
mutex io;
log (string _dir, bool _isKeepOpen = true, bool _printInConsole = false);

@ -43,6 +43,7 @@ void log::setMoment() {
}
void log::put(string logline) {
io.lock();
if (printInConsole) {
cout << logline << endl;
}
@ -74,6 +75,7 @@ void log::put(string logline) {
if (!isKeepOpen && logfile.is_open()) {
loose();
}
io.unlock();
}

Loading…
Cancel
Save