FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTLogger.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Qu�bec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifndef FMTlogger_Hm_included
9#define FMTlogger_Hm_included
10#include <boost/serialization/export.hpp>
11#include <boost/thread/recursive_mutex.hpp>
12#include <fstream>
13#include <string>
14#include <memory>
15#include "FMTException.h"
16
17namespace boost
18{
19 namespace serialization
20 {
21 class access;
22 }
23}
24
25
27namespace Logging
28{
29 class FMTSolverLogger;
30 //class CoinMessageHandler;
31 // DocString: FMTLogger
37 {
38 public:
39 // DocString: FMTLogger()
44 // DocString: ~FMTLogger()
48 virtual ~FMTLogger();
49 // DocString: FMTLogger(const FMTLogger&)
54 FMTLogger(const FMTLogger& rhs);
55 // DocString: FMTLogger::redirectToFile
61 void redirectToFile(const std::string& filename, bool logStamp = true);
62 // DocString: FMTLogger::closeFileStream
67 // DocString: FMTLogger::operator=
73 FMTLogger& operator = (const FMTLogger& rhs);
74 #ifdef FMTWITHOSI
75 // DocString: FMTLogger::print
80 virtual int print();
81 // DocString: FMTLogger::checkSeverity
85 virtual void checkSeverity();
86 // DocString: FMTLogger::clone
91 virtual FMTLogger* clone() const=0;
92 #endif
93 // DocString: FMTLogger::getLogStamp
98 virtual std::string getLogStamp() const;
99 // DocString: FMTLogger::logStamp
103 virtual void logStamp();
104 // DocString: FMTLogger::logTime
108 virtual void logTime();
109 // DocString: FMTLogger::setStreamFlush
114 void setStreamFlush(bool flush);
115 // DocString: FMTLogger::operator<<(const std::string& msg)
121 virtual FMTLogger& operator<<(const std::string& msg);
122 // DocString: FMTLogger::operator<<(const int& msg)
128 virtual FMTLogger& operator<<(const int& msg);
129 // DocString: FMTLogger::operator<<(const double& msg)
135 virtual FMTLogger& operator<<(const double& msg);
136 // DocString: FMTLogger::operator<<(const float& msg)
142 virtual FMTLogger& operator<<(const float& msg);
143 // DocString: FMTLogger::operator<<(const std::time_t& msg)
149 virtual FMTLogger& operator<<(const std::time_t& msg);
150 // DocString: FMTLogger::operator<<(const size_t& msg)
156 virtual FMTLogger& operator<<(const size_t& msg);
157 // DocString: FMTLogger::operator<<(const unsigned int& msg)
163 virtual FMTLogger& operator<<(const unsigned int& msg);
164 // DocString: FMTLogger::operator<<(const void*& msg)
170 virtual FMTLogger& operator<<(const void*& msg);
171 // DocString: FMTLogger::logWithLevel
179 virtual bool logWithLevel(const std::string& p_msg, const int& p_messageLevel) const;
180 #ifdef FMTWITHOSI
181 // DocString: FMTLogger::getSolverLogger
187 #endif
188 // DocString: FMTLogger::Clone
193 virtual std::unique_ptr <FMTLogger> Clone() const = 0;
194 protected:
195 #if defined FMTWITHOSI
196 std::unique_ptr<FMTSolverLogger>m_solverref;
197 #endif
198 // DocString: FMTLogger::pathtostream
200 std::string m_filepath;
201 // DocString: FMTLogger::m_FileStream
203 mutable std::unique_ptr<std::ofstream>m_FileStream;
204 // DocString: FMTLogger::m_mtx
206 //mutable std::recursive_mutex mtx;
207 mutable boost::recursive_mutex m_mtx;
208 // DocString: FMTLogger::m_flushstream
211 // DocString: FMTLogger::_cout
216 virtual void _cout(const char* message) const;
217 #ifdef FMTWITHOSI
218 // DocString: FMTLogger::_setLoggingLevel
223 virtual void _setLoggingLevel(const int& level);
224 #endif // FMTWITHOSI
225 private:
226 friend class boost::serialization::access;
227 // DocString: FMTLogger::save
234 template<class Archive>
235 void save(Archive& ar, const unsigned int version) const;
236 // DocString: FMTLogger::load
243 template<class Archive>
244 void load(Archive& ar, const unsigned int version);
245 // DocString: FMTLogger::serialize
252 template<class Archive>
253 void serialize(Archive& ar, const unsigned int file_version);
254 // DocString: FMTLogger::_setToFile
259 void _setToFile(const std::string& filename) const;
260
261 };
262
263}
264
265BOOST_CLASS_EXPORT_KEY(Logging::FMTLogger)
266
267#endif
#define FMTEXPORT
Definition: FMTutility.h:125
Base class handling the level of information printed by FMT.
Definition: FMTLogger.h:37
virtual int print()
Print function overloaded from CoinMessageHandler when using the OSI solver interface.
virtual FMTLogger & operator<<(const float &msg)
Append a float to the log.
virtual FMTLogger & operator<<(const int &msg)
Append an int to the log.
virtual FMTLogger & operator<<(const double &msg)
Append a double to the log.
FMTLogger()
Default constructor for FMTLogger.
virtual void checkSeverity()
Check the severity of the message to be printed by the CoinMessageHandler base class.
virtual FMTLogger & operator<<(const unsigned int &msg)
Append an unsigned int to the log.
virtual ~FMTLogger()
Default destructor for FMTLogger.
virtual void _setLoggingLevel(const int &level)
Set the solver logger logging level.
bool m_flushstream
If true will flush stream at each write.
Definition: FMTLogger.h:210
virtual std::string getLogStamp() const
Return the basic log stamp as a string.
std::string m_filepath
string path the the potential filestream
Definition: FMTLogger.h:200
virtual std::unique_ptr< FMTLogger > Clone() const =0
clone the FMTLogger
virtual FMTLogger & operator<<(const std::time_t &msg)
Append a std::time_t to the log.
virtual void logStamp()
Log information about the version of FMT and its build date.
virtual FMTSolverLogger * getSolverLogger()
Return the abstract logger used by the OSI solver interface.
virtual FMTLogger & operator<<(const size_t &msg)
Append a size_t to the log.
virtual FMTLogger & operator<<(const std::string &msg)
Append a string to the log.
void setStreamFlush(bool flush)
Force the flushing of the file stream.
virtual FMTLogger & operator<<(const void *&msg)
Append the address of a void pointer to the log.
void redirectToFile(const std::string &filename, bool logStamp=true)
Redirect the log information to a file.
virtual FMTLogger * clone() const =0
Clone the logger, needed for the abstract CoinMessageHandler usage.
std::unique_ptr< std::ofstream > m_FileStream
stream if the logger redirect the logging into somesort of file.
Definition: FMTLogger.h:203
void closeFileStream()
Close the file stream.
FMTLogger(const FMTLogger &rhs)
Copy constructor for FMTLogger.
virtual void _cout(const char *message) const
Output a message, sometimes needed on Windows with boost::python to print directly into the Python wi...
virtual bool logWithLevel(const std::string &p_msg, const int &p_messageLevel) const
Log a message with a given message level if message level is greater of equal to the logger level the...
boost::recursive_mutex m_mtx
Mutex for multi-threading.
Definition: FMTLogger.h:207
virtual void logTime()
Log the actual time at which the function is called.
std::unique_ptr< FMTSolverLogger > m_solverref
Definition: FMTLogger.h:196
Abstract logger used with the OSI solver interface (CoinMessageHandler).
Definition: FMTSolverLogger.h:25
Namespace for the log management, provides different log handlers.
Definition: FMTDebugLogger.h:14
Definition: FMTAction.h:463