monolish  0.14.0
MONOlithic LIner 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  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
monolish::Logger::pStream
std::ostream * pStream
Definition: monolish_logger.hpp:32
monolish::Logger::set_log_level
void set_log_level(size_t L)
Specifying the log level.
Definition: monolish_logger.hpp:58
monolish::Logger::calls
std::vector< std::string > calls
Definition: monolish_logger.hpp:27
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::Logger::func_out
void func_out()
Definition: logger_utils.cpp:80
monolish::Logger::solver_in
void solver_in(const std::string func_name)
Definition: logger_utils.cpp:7
monolish::Logger::operator=
Logger & operator=(const Logger &)=delete
monolish::Logger::util_out
void util_out()
Definition: logger_utils.cpp:123
monolish::Logger::set_log_filename
void set_log_filename(const std::string file)
Specifying the log finename.
Definition: monolish_logger.hpp:70
monolish::Logger::filename
std::string filename
Definition: monolish_logger.hpp:31
monolish::Logger::util_in
void util_in(const std::string func_name)
Definition: logger_utils.cpp:113
monolish::Logger::Logger
Logger()=default
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::Logger::solver_out
void solver_out()
Definition: logger_utils.cpp:35
monolish::Logger::LogLevel
size_t LogLevel
Definition: monolish_logger.hpp:35
monolish::Logger::~Logger
~Logger()
Definition: monolish_logger.hpp:23
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::Logger::times
std::vector< std::chrono::system_clock::time_point > times
Definition: monolish_logger.hpp:30
monolish::Logger::func_in
void func_in(const std::string func_name)
Definition: logger_utils.cpp:69