AQUAgpusph 4.1.2
Loading...
Searching...
No Matches
Logger.h
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
24#ifndef LOGGER_H_INCLUDED
25#define LOGGER_H_INCLUDED
26
27#include <sphPrerequisites.h>
28
29#include <string>
30#include <fstream>
31#include <vector>
32#if __APPLE__
33#include <OpenCL/cl.h>
34#else
35#include <CL/cl.h>
36#endif
37
38#ifdef HAVE_NCURSES
39#include <ncurses.h>
40#endif
41
42#include <InputOutput/Report.h>
43#include <Singleton.h>
44
45#ifndef addMessageF
50#define addMessageF(level, log) addMessage(level, log, __METHOD_CLASS_NAME__)
51#endif
52
53#ifndef LOG
59#define LOG(level, log) \
60 Aqua::InputOutput::Logger::singleton()->addMessageF(level, log)
61#endif
62#ifndef LOG0
68#define LOG0(level, log) \
69 Aqua::InputOutput::Logger::singleton()->addMessage(level, log)
70#endif
71
72namespace Aqua {
73
75{
80};
81
82namespace InputOutput {
83
91struct Logger
92 : public Aqua::Singleton<Aqua::InputOutput::Logger>
94{
95 public:
97 Logger();
98
100 ~Logger();
101
107 void initNCurses();
108
113 void endNCurses();
114
119 void initFrame();
120
125 void endFrame();
126
149 void writeReport(std::string msg,
150 std::string color = "white",
151 bool bold = false);
152
163 void addMessage(TLogLevel level, std::string log, std::string func = "");
164
168 void printDate(TLogLevel level = L_DEBUG);
169
174 void printOpenCLError(cl_int error, TLogLevel level = L_DEBUG);
175
180 void save(float t){};
181
182 protected:
188 void printLog();
189
192 void refreshAll();
193
195 void open();
196
198 void close();
199
200 private:
202 int _last_row;
203
205 struct timeval _start_time;
207 struct timeval _actual_time;
208
210 std::vector<int> _log_level;
212 std::vector<std::string> _log;
214 std::ofstream _log_file;
215};
216
217}
218} // namespace
219
220#endif // LOGGER_H_INCLUDED
Base class for all the report file managers. (See Aqua::InputOutput::Report for details)
Singleton instance. (See Aqua::Singleton for details)
Base class for all the report file managers.
Definition: Report.h:56
Simple but versatile singleton instance (Meyers singleton).
Definition: Singleton.h:57
Main AQUAgpusph namespace.
Definition: ArgumentsManager.cpp:45
TLogLevel
Definition: Logger.h:75
@ L_ERROR
Definition: Logger.h:79
@ L_WARNING
Definition: Logger.h:78
@ L_DEBUG
Definition: Logger.h:76
@ L_INFO
Definition: Logger.h:77
Set of definitions and macros related with the implementation.
On screen and log file output manager.
Definition: Logger.h:94
void printLog()
Print the log record.
Definition: Logger.cpp:470
void initFrame()
Call to setup a new terminal frame.
Definition: Logger.cpp:92
void open()
Create the log file.
Definition: Logger.cpp:541
void endNCurses()
Transform the terminal into an ncurses one.
Definition: Logger.cpp:78
void save(float t)
Do nothing.
Definition: Logger.h:180
void printOpenCLError(cl_int error, TLogLevel level=L_DEBUG)
Print an OpenCL error.
Definition: Logger.cpp:312
Logger()
Constructor.
Definition: Logger.cpp:46
void initNCurses()
Transform the terminal into an ncurses one.
Definition: Logger.cpp:60
void refreshAll()
Definition: Logger.cpp:532
~Logger()
Destructor.
Definition: Logger.cpp:54
void writeReport(std::string msg, std::string color="white", bool bold=false)
Write a new message in the terminal output.
Definition: Logger.cpp:130
void addMessage(TLogLevel level, std::string log, std::string func="")
Add a new log record message.
Definition: Logger.cpp:226
void close()
Close the log file.
Definition: Logger.cpp:568
void endFrame()
Call to refresh the terminal frame.
Definition: Logger.cpp:119
void printDate(TLogLevel level=L_DEBUG)
Print a time stamp in the screen and the log file.
Definition: Logger.cpp:301