21 #include <itkOutputWindow.h>
22 #include <itkSimpleFastMutexLock.h>
44 FormatSmart(l, (
int)GetCurrentThreadId());
52 FormatFull(*
logFile, l, (
int)GetCurrentThreadId());
70 itk::OutputWindow::GetInstance()->DisplayText(
outputWindow->str().c_str());
90 mitkLogBackend =
nullptr;
99 std::string closedFileName;
114 MITK_INFO <<
"closing logfile (" << closedFileName <<
")";
126 logFile->open(file, std::ios_base::out | std::ios_base::app);
138 MITK_WARN <<
"opening logfile '" << file <<
"' for writing failed";
154 for (r = 1; r < argc; r++)
156 if (std::string(argv[r]) ==
"--logfile")
161 MITK_ERROR <<
"--logfile parameter found, but no file given";
167 for (r += 2; r < argc; r++)
168 argv[r - 2] = argv[r];
178 static const int numLogFiles = 10;
179 std::string newEmptyLogFileName;
182 newEmptyLogFileName = IncrementLogFileNames(prefixPath, numLogFiles);
193 s << prefixPath.c_str() <<
"-" << numLogFiles - 1 <<
".log";
195 if (CheckIfFileExists(s.str()))
197 int retVal = ::remove(s.str().c_str());
201 <<
"Problem while deleting the oldest log file. Maybe the access to this files is blocked. Aborting!";
207 for (
int r = numLogFiles - 1; r >= 1; r--)
209 std::stringstream dst;
210 dst << prefixPath.c_str() <<
"-" << r <<
".log";
212 std::stringstream src;
213 src << prefixPath.c_str() <<
"-" << r - 1 <<
".log";
216 if (CheckIfFileExists(src.str()))
218 int retVal = ::rename(src.str().c_str(), dst.str().c_str());
221 mitkThrow() <<
"Problem while renaming the log files. Maybe the access to this files is blocked. Aborting!";
229 s << prefixPath.c_str() <<
"-0.log";
236 bool returnValue =
false;
237 std::ifstream
File(filename.c_str());
static mitk::LoggingBackend * mitkLogBackend
void MBILOG_EXPORT UnregisterBackend(BackendBase *backend)
Unregisters a backend.
static void Register()
registers MITK logging backend at mbilog
static bool logOutputWindow
void ProcessMessage(const mbilog::LogMessage &) override
overloaded method for receiving log message from mbilog
virtual mbilog::OutputType GetOutputType() const override
static itk::SimpleFastMutexLock logMutex
static void RotateLogFiles(const std::string &prefixPath)
Activates and handles a rolling log file with the given prefix and path. This method handles 10 log f...
static std::stringstream * outputWindow
static bool CheckIfFileExists(const std::string &filename)
An object of this class represents a single logging message (logging event) of the mbi logging mechan...
static const std::string filename
void MBILOG_EXPORT RegisterBackend(BackendBase *backend)
Registeres a backend to the mbi logging mechanism. If a backend is registered here, all mbilog messages are relayed to this backend through the method ProcessMessage. If no backend is registered the default backend is used.
mbilog backend implementation for mitk
static std::ofstream * logFile
static std::string IncrementLogFileNames(const std::string &prefixPath, int numLogFiles=10)
Increments the names of logfiles with the given prefixPath. This means, if the prefixPath is "myLogFi...
static void EnableAdditionalConsoleWindow(bool enable)
Enables an additional logging output window by means of itk::outputwindow This might be relevant for ...
static void SetLogFile(const char *file)
Sets extra log file path (additionally to the console log)
static void CatchLogFileCommandLineParameter(int &argc, char **argv)
Automatically extracts and removes the "--logfile " parameters from the standard C main(argc...
static std::string GetLogFile()
static void Unregister()
Unregisters MITK logging backend at mbilog.
static std::string logFileName