MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkUSNavigationLoggingBackend.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
15#include <mitkCommon.h>
16
20
22{
23 if ( m_OutputStream.is_open() ) { m_OutputStream.close(); }
24}
25
27{
28 if ( m_OutputStream.is_open() ) { m_OutputStream.close(); }
29
30 m_OutputStream.open(filename.c_str());
31 if ( ! m_OutputStream.is_open() )
32 {
33 MITK_ERROR("USNavigationLoggingBackend")
34 << "File '" << filename << "' cannot be opened for logging.";
35 mitkThrow() << "File '" << filename << "' cannot be opened for logging.";
36 }
37}
38
39void mitk::USNavigationLoggingBackend::ProcessMessage(const LogMessage& logMessage)
40{
41 if ( m_OutputStream.is_open()) {this->FormatSmart(m_OutputStream, logMessage);}
42 if (logMessage.Category == "USNavigationLogging")
43 {
44 m_lastNavigationMessages.push_back(logMessage.Message);
45 m_allNavigationMessages.push_back(logMessage.Message);
46 }
47}
48
50{
51return m_lastNavigationMessages;
52}
53
55{
56 std::ofstream csvStream;
57 csvStream.open(filename.c_str());
58 if ( ! csvStream.is_open() ) {MITK_ERROR("USNavigationLoggingBackend") << "File '" << filename << "' cannot be opened for logging."; return;}
59 for (std::size_t i = 0; i < m_allNavigationMessages.size(); i++)
60 {
61 csvStream << m_allNavigationMessages.at(i) << "\n";
62 }
63 csvStream.close();
64}
65
67{
68m_lastNavigationMessages = std::vector<std::string>();
69}
70
71mitk::LogBackendBase::OutputType mitk::USNavigationLoggingBackend::GetOutputType() const
72{
73 return OutputType::File;
74}
void ProcessMessage(const LogMessage &logMessage) override
This method is called by the mbi logging mechanism if the object is registered in the mbi logging mec...
void WriteCSVFileWithNavigationMessages(std::string filename)
void SetOutputFileName(std::string filename)
Set file path und name for the output file. The file will be opened and all log messages will be dire...