OoOJoin  0.0.1
The next generation of out-of-order join operator
IntelliLog.h
1 
2 #ifndef _UTILS_IntelliLog_H_
3 #define _UTILS_IntelliLog_H_
4 #pragma once
5 #include <string>
6 #include <iostream>
7 #include <sstream>
8 #include <chrono>
9 #include <iostream>
10 #include <source_location>
11 #include <ctime>
12 #include <mutex>
13 #include <fstream>
21 using namespace std;
22 namespace INTELLI {
28 class IntelliLog {
29  public:
37  static void log(std::string level,
38  std::string_view message,
39  std::source_location const source = std::source_location::current());
44  static void setupLoggingFile(string fname);
45 };
53  private:
54  std::mutex m_mut;
55  ofstream of;
56  bool isOpened = false;
57  public:
60  if (isOpened) {
61  of.close();
62  }
63  }
67  void lock() {
68  while (!m_mut.try_lock());
69  }
73  void unlock() {
74  m_mut.unlock();
75  }
80  void openLogFile(string fname) {
81  of.open(fname, std::ios_base::app);
82  if (of.fail()) {
83  return;
84  }
85  isOpened = true;
86  }
91  void appendLogFile(string msg) {
92  if (!isOpened) {
93  return;
94  }
95  lock();
96  of << msg;
97  unlock();
98  }
99 };
105 #define INTELLI_INFO(n) IntelliLog::log("INFO",n)
111 #define INTELLI_ERROR(n) IntelliLog::log("ERROR",n)
117 #define INTELLI_WARNING(n) IntelliLog::log("WARNING",n)
123 #define INTELLI_DEBUG(n) IntelliLog::log("DEBUG",n)
124 }
125 #endif
The protector for concurrent log on a file.
Definition: IntelliLog.h:52
The log functions packed in class.
Definition: IntelliLog.h:28
void openLogFile(string fname)
try to open a file
Definition: IntelliLog.h:80
void unlock()
unlock this protector
Definition: IntelliLog.h:73
void appendLogFile(string msg)
try to appened something to the file, if it's opened
Definition: IntelliLog.h:91
void lock()
lock this protector
Definition: IntelliLog.h:67