DamBreak++ Wave Simulator 0.3
DamBreak++ Simulation Framework
Loading...
Searching...
No Matches
Sfx_Logger.h
Go to the documentation of this file.
1
2#pragma once
3
4// C++ includes
5#include <cstdio>
6#include <fstream>
7#include <filesystem>
8// SfxBase19 lib includes
9#include "include/Sfx_Object.h"
10#include "include/Sfx_ILogger.h"
11#include "include/Singleton.hpp"
12
13namespace Sfx
14{
15 // Design Note (January 16, 2011)
16 // We inherit from Object, it's because we use the Global insertProvider(Object*).
17 // In the actual implementation of Object it doesn't make sense, it's only for debugging.
18 // In our migration towards the new architecture this inheritance will be revised.
19 // Probably insertProvider(Provider*) would be more appropriate of inserting Object*
20 //
21 // febuary 3rd, 2018
22 // This class still under construction (we are merging many version of the Logger
23 // implementation). Final version will used in the new version of the API Dbpp.
24
34 class Logger : public Sfx::Singleton<Logger>,
35 public Sfx::Object,
36 public virtual Sfx::ILogger
37 {
38 public:
42 enum class eOpeningMode { fstream = 0, FILE = 1 };
43
48 bool Init();
53 bool Shutdown();
57 void OutputNewline();
63 void OutputError(char* text, ...);
69 void OutputSuccess(char* text, ...);
74 void write2File(const std::string aMessage);
75 // NOTE in the current version we support 2 mode for writing
76 // to log file. This is because we have merged different version
77 // of the logger and we want back compatibility
83 void setOpeningMode(const eOpeningMode aOpenMode)
84 {
86 {
87 // check if file is open
88 if (m_fStream.is_open())
89 {
90 m_fStream.close();
91 }
92 m_openMode = aOpenMode;
93 }
94 }
95
96 //
97 // ILogger interface
98 //
99
100 //static Logger* Instance();
101
107 bool openLogFile( std::string logFile);
112 void writeToLogFile( const std::string aStr);
118
122 friend class Singleton<Logger>;
123
124 protected:
128 Logger();
132 ~Logger();
133
138 Logger(const Logger& aOther) = delete;
144 Logger& operator= (const Logger& aOther) = delete;
146 bool m_opened;
148 std::string m_fileName;
149 std::filesystem::path m_filePath;
150 std::ofstream m_fStream;
151 char m_logFileNAME[256];
155 void close();
156 };
157} // End of namespace
bool openLogFile(std::string logFile)
Open file for writing result of the simulation.
Definition Sfx_Logger.cxx:205
eOpeningMode m_openMode
Definition Sfx_Logger.h:147
FILE * m_logfile
Definition Sfx_Logger.h:145
Logger & operator=(const Logger &aOther)=delete
prevent assignment
bool closeLogFile()
Close file.
Definition Sfx_Logger.cxx:244
char m_logFileNAME[256]
Definition Sfx_Logger.h:151
eOpeningMode
Opening file mode.
Definition Sfx_Logger.h:42
@ FILE
Definition Sfx_Logger.h:42
@ fstream
Definition Sfx_Logger.h:42
void OutputSuccess(char *text,...)
outpout success message to log file
Definition Sfx_Logger.cxx:162
std::filesystem::path m_filePath
Definition Sfx_Logger.h:149
Logger(const Logger &aOther)=delete
prevent copy and assignment
void write2File(const std::string aMessage)
writing log event to file
Definition Sfx_Logger.cxx:196
void writeToLogFile(const std::string aStr)
Write to log file.
Definition Sfx_Logger.cxx:237
eOpeningMode getOpeningMode()
Definition Sfx_Logger.h:78
void close()
close file if opened
Definition Sfx_Logger.cxx:188
std::ofstream m_fStream
Definition Sfx_Logger.h:150
void setOpeningMode(const eOpeningMode aOpenMode)
Open file for writing result of the simulation.
Definition Sfx_Logger.h:83
bool Init()
Initiates log. Don't call, it is in the constructor.
Definition Sfx_Logger.cxx:46
void OutputError(char *text,...)
outpout error message to log file
Definition Sfx_Logger.cxx:127
~Logger()
Destructor.
Definition Sfx_Logger.cxx:38
bool m_opened
Definition Sfx_Logger.h:146
std::string m_fileName
Definition Sfx_Logger.h:148
void OutputNewline()
outpout newline to log file
Definition Sfx_Logger.cxx:104
Logger()
Default ctor.
Definition Sfx_Logger.cxx:14
bool Shutdown()
Shuts down log, in the destructor.
Definition Sfx_Logger.cxx:90
Definition HydUtils.h:15