AQUAgpusph 5.0.4
Loading...
Searching...
No Matches
Logger.hpp
Go to the documentation of this file.
1/*
2 * This file is part of AQUAgpusph, a free CFD program based on SPH.
3 * Copyright (C) 2012 Jose Luis Cercos Pita <jl.cercos@upm.es>
4 *
5 * AQUAgpusph is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * AQUAgpusph is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with AQUAgpusph. If not, see <http://www.gnu.org/licenses/>.
17 */
18
23
24#ifndef LOGGER_H_INCLUDED
25#define LOGGER_H_INCLUDED
26
28
29#include <string>
30#include <fstream>
31#include <vector>
32#include <mutex>
33#if __APPLE__
34#include <OpenCL/cl.h>
35#else
36#include <CL/cl.h>
37#endif
38
39#include "Report.hpp"
40
41#ifndef addMessageF
46#define addMessageF(level, log) addMessage(level, log, __METHOD_CLASS_NAME__)
47#endif
48
49#ifndef LOG
55#define LOG(level, log) \
56 Aqua::InputOutput::Logger::singleton()->addMessageF(level, log)
57#endif
58#ifndef LOG0
64#define LOG0(level, log) \
65 Aqua::InputOutput::Logger::singleton()->addMessage(level, log)
66#endif
67
68namespace Aqua {
69
78
79namespace InputOutput {
80
90{
91public:
93 ~Logger();
94
95 // Deleting the copy constructor to prevent copies
96 Logger(const Logger& obj) = delete;
97
103 static Logger* singleton();
104
108 inline void setLevel(int level)
109 {
110 _level = (std::min)((std::max)(level, (int)L_DEBUG), (int)L_NONE);
111 }
112
119 void writeReport(std::string msg);
120
131 void addMessage(TLogLevel level, std::string log, std::string func = "");
132
136 void printDate(TLogLevel level = L_DEBUG);
137
142 void printOpenCLError(cl_int error, TLogLevel level = L_DEBUG);
143
148 void save(float UNUSED_PARAM t) {};
149
150 protected:
152 void open();
153
155 void close();
156
157 private:
162 Logger();
163
165 int _level;
166
168 std::ofstream _log_file;
169
171 std::recursive_mutex _mutex;
172};
173
174}
175} // namespace
176
177#endif // LOGGER_H_INCLUDED
Base class for all the report file managers. (See Aqua::InputOutput::Report for details)
On screen and log file output manager.
Definition Logger.hpp:90
void save(float UNUSED_PARAM t)
Do nothing.
Definition Logger.hpp:148
static Logger * singleton()
Get –creating it the first time– the logger instance.
Definition Logger.cpp:64
Logger(const Logger &obj)=delete
void setLevel(int level)
Set the log level.
Definition Logger.hpp:108
Base class for all the report file managers.
Definition Report.hpp:56
Main AQUAgpusph namespace.
Definition ArgumentsManager.cpp:50
TLogLevel
Definition Logger.hpp:71
@ L_ERROR
Definition Logger.hpp:75
@ L_WARNING
Definition Logger.hpp:74
@ L_DEBUG
Definition Logger.hpp:72
@ L_INFO
Definition Logger.hpp:73
@ L_NONE
Definition Logger.hpp:76
Set of definitions and macros related with the implementation.
#define UNUSED_PARAM
Definition sphPrerequisites.hpp:391
#define DECLDIR
Prefix to export C functions on the compiled library.
Definition sphPrerequisites.hpp:65