GraviDy  1.0
Gravitational Dynamics N-body integrator
Logger.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016
3  *
4  * Cristián Maureira-Fredes <cmaureirafredes@gmail.com>
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * 3. The name of the author may not be used to endorse or promote
20  * products derived from this software without specific prior written
21  * permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  */
36 #ifndef LOGGER_HPP
37 #define LOGGER_HPP
38 #include "../common.hpp"
39 #include "../NbodySystem.hpp"
40 #include <cctype>
41 
42 const std::string color_black = "\033[0;30m";
43 const std::string color_red = "\033[0;31m";
44 const std::string color_green = "\033[0;32m";
45 const std::string color_yellow = "\033[0;33m";
46 const std::string color_blue = "\033[0;34m";
47 const std::string color_purple = "\033[0;35m";
48 const std::string color_cyan = "\033[0;36m";
49 const std::string color_white = "\033[0;37m";
50 const std::string color_disable = "\033[m";
51 
52 #define SSTR( x ) static_cast< std::ostringstream & >( \
53  ( std::ostringstream() << std::dec << x ) ).str()
54 
60 class Logger {
61  public:
63  ~Logger();
64 
66 
68  std::ofstream out_file;
69  std::ofstream info_file;
70  std::ostream *gstream;
71  std::string ofname;
72  std::string ofname_info;
73 
74  std::string get_timestamp();
75  void print_info();
76  void add_info(std::string key, std::string value);
77  void write_info();
78  void write_snapshot(unsigned int snapshot_number, double ITIME);
79  void print_all(double ITIME, unsigned int snapshot_number);
80  void print_energy_log(double ITIME, unsigned int iterations,
81  long long interactions, unsigned int nsteps,
82  double new_energy);
83  void print_lagrange_radii(double ITIME, std::vector<double> lagrange_radii);
84 
85 
86  void log(int type, std::string msg);
87  void log_error(std::string msg);
88  void log_warning(std::string msg);
89  void log_success(std::string msg);
90  void log_info(std::string msg);
91 };
92 
93 #endif // LOGGER_HPP
Class in charge of all the logging system in the code.
Definition: Logger.hpp:60
const std::string color_yellow
Definition: Logger.hpp:45
std::ofstream out_file
Definition: Logger.hpp:68
void write_snapshot(unsigned int snapshot_number, double ITIME)
Definition: Logger.cpp:77
std::string ofname_info
Definition: Logger.hpp:72
bool print_screen
Definition: Logger.hpp:67
~Logger()
Definition: Logger.cpp:53
const std::string color_purple
Definition: Logger.hpp:47
Class in charge of the general aspects of the N-body integrator.
Definition: NbodySystem.hpp:51
void print_all(double ITIME, unsigned int snapshot_number)
Definition: Logger.cpp:270
const std::string color_white
Definition: Logger.hpp:49
const std::string color_black
Definition: Logger.hpp:42
void log_info(std::string msg)
Definition: Logger.cpp:432
void print_lagrange_radii(double ITIME, std::vector< double > lagrange_radii)
Definition: Logger.cpp:239
std::string ofname
Definition: Logger.hpp:71
NbodySystem * ns
Definition: Logger.hpp:65
std::string get_timestamp()
Definition: Logger.cpp:58
void log_error(std::string msg)
Definition: Logger.cpp:417
const std::string color_cyan
Definition: Logger.hpp:48
void print_energy_log(double ITIME, unsigned int iterations, long long interactions, unsigned int nsteps, double new_energy)
Definition: Logger.cpp:324
void write_info()
Definition: Logger.cpp:136
const std::string color_blue
Definition: Logger.hpp:46
Logger(NbodySystem *ns)
Definition: Logger.cpp:38
const std::string color_green
Definition: Logger.hpp:44
std::ofstream info_file
Definition: Logger.hpp:69
const std::string color_disable
Definition: Logger.hpp:50
void print_info()
Definition: Logger.cpp:219
std::ostream * gstream
Definition: Logger.hpp:70
void log(int type, std::string msg)
Definition: Logger.cpp:393
void log_warning(std::string msg)
Definition: Logger.cpp:422
const std::string color_red
Definition: Logger.hpp:43
void add_info(std::string key, std::string value)
Definition: Logger.cpp:113
void log_success(std::string msg)
Definition: Logger.cpp:427