Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#ifndef LOGGER_H
24#define LOGGER_H
25
26#include <fstream>
27#include <sstream>
28#include <mpi.h>
29
49class Logger {
50public:
51 Logger();
52 ~Logger();
53
54 void clear() {outStream.clear();}
55 bool close();
56 bool flush(bool verbose);
57 std::stringstream& getStream() {return outStream;}
58 bool open(MPI_Comm comm,const int& MASTERRANK,const std::string& fname,const bool& append=false);
59 bool print(const std::string& s);
60 std::string str() {return outStream.str();}
61
62 // ****************************************
63 // ****** STREAM INSERTION OPERATORS ******
64 // ****************************************
65
66 template<typename T> inline Logger& operator<<(const T& value);
67 Logger& operator<<(Logger& (*pf)(Logger&));
68 Logger& operator<<(std::ostream& (*pf)(std::ostream& ));
69
70private:
71 bool fileOpen;
72 int mpiRank;
74 std::stringstream outStream;
75 std::fstream* masterStream;
76};
77
83template<typename T>
84Logger& Logger::operator<<(const T& value) {
85 outStream << value;
86 return *this;
87}
88
89Logger& writeVerbose(Logger& logger);
90Logger& write(Logger& logger);
91
92#endif
bool open(MPI_Comm comm, const int &MASTERRANK, const std::string &fname, const bool &append=false)
Open a logfile.
Definition logger.cpp:117
int masterRank
Definition logger.h:73
bool fileOpen
Definition logger.h:71
std::string str()
Definition logger.h:60
std::stringstream & getStream()
Definition logger.h:57
int mpiRank
Definition logger.h:72
Logger & operator<<(const T &value)
Definition logger.h:84
bool print(const std::string &s)
Definition logger.cpp:135
std::fstream * masterStream
Definition logger.h:75
bool flush(bool verbose)
Definition logger.cpp:67
Logger()
Definition logger.cpp:32
~Logger()
Definition logger.cpp:39
void clear()
Definition logger.h:54
bool close()
Definition logger.cpp:51
std::stringstream outStream
Definition logger.h:74
Logger & writeVerbose(Logger &logger)
Definition logger.cpp:177
Logger & write(Logger &logger)
Definition logger.cpp:193