monolish  0.17.3-dev.16
MONOlithic LInear equation Solvers for Highly-parallel architecture
monolish_logger.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <chrono>
3 #include <fstream>
4 #include <iostream>
5 #include <omp.h>
6 #include <string>
7 #include <vector>
8 
9 #define monolish_func __FUNCTION__
10 
11 #if defined USE_MPI
12 #include <mpi.h>
13 #endif
14 
15 namespace monolish {
19 class Logger {
20 private:
21  Logger() = default;
22 
23  ~Logger() {
24  if (pStream != &std::cout) {
25  delete pStream;
26  }
27  };
28 
29  std::vector<std::string> calls;
30  std::vector<std::chrono::system_clock::time_point> times;
31  std::string filename;
32  std::ostream *pStream;
33 
34 public:
35  size_t LogLevel = 0;
36 
37  Logger(const Logger &) = delete;
38  Logger &operator=(const Logger &) = delete;
39  Logger(Logger &&) = delete;
40  Logger &operator=(Logger &&) = delete;
41 
42  [[nodiscard]] static Logger &get_instance() {
43  static Logger instance;
44  return instance;
45  }
46 
58  void set_log_level(size_t L) {
59  if (3 < L) { // loglevel = {0, 1, 2, 3}
60  throw std::runtime_error("error bad LogLevel");
61  }
62  LogLevel = L;
63  }
64 
70  void set_log_filename(const std::string file) {
71  filename = file;
72 
73  // file open
74  pStream = new std::ofstream(filename);
75  if (pStream->fail()) {
76  delete pStream;
77  pStream = &std::cout;
78  }
79  }
80 
81  // for solver (large func.)
82  void solver_in(const std::string func_name);
83  void solver_out();
84 
85  // for blas (small func.)
86  void func_in(const std::string func_name);
87  void func_out();
88 
89  // for utils (very small func.)
90  void util_in(const std::string func_name);
91  void util_out();
92 };
93 } // namespace monolish
logger class (singleton, for developper class)
void util_in(const std::string func_name)
void solver_in(const std::string func_name)
std::string filename
Logger(Logger &&)=delete
std::ostream * pStream
std::vector< std::string > calls
void set_log_filename(const std::string file)
Specifying the log finename.
Logger & operator=(Logger &&)=delete
static Logger & get_instance()
void func_in(const std::string func_name)
Logger & operator=(const Logger &)=delete
Logger()=default
void set_log_level(size_t L)
Specifying the log level.
std::vector< std::chrono::system_clock::time_point > times
Logger(const Logger &)=delete
monolish namespaces