Medical Imaging Interaction Toolkit  2018.4.99-bd7b41ba
Medical Imaging Interaction Toolkit
mitk::LoggingBackend Class Reference

mbilog backend implementation for mitk More...

#include <mitkLog.h>

Inheritance diagram for mitk::LoggingBackend:
Collaboration diagram for mitk::LoggingBackend:

Public Member Functions

void ProcessMessage (const mbilog::LogMessage &) override
 overloaded method for receiving log message from mbilog More...
 
mbilog::OutputType GetOutputType () const override
 
- Public Member Functions inherited from mbilog::TextBackendBase
 ~TextBackendBase () override
 
- Public Member Functions inherited from mbilog::BackendBase
virtual ~BackendBase ()
 

Static Public Member Functions

static void Register ()
 registers MITK logging backend at mbilog More...
 
static void Unregister ()
 Unregisters MITK logging backend at mbilog. More...
 
static void SetLogFile (const char *file)
 Sets extra log file path (additionally to the console log) More...
 
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 files with a given prefix, e.g. "myLogFile". The 10 log files will then look like this: myLogFile-0.log (current file) myLogFile-1.log (last file) myLogFile-2.log [...] myLogFile-9.log. More...
 
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 "myLogFile" myLogFile-0.log is renamed to myLogFile-1.log, myLogFile-1.log to myLogFile-2.log, and so on. The oldest logfile is deleted. The number of log files is defined by the parameter "numLogFiles". The first logfile name is "free" (e.g., [prefix]-0.log) again. This name is retured. More...
 
static std::string GetLogFile ()
 
static void EnableAdditionalConsoleWindow (bool enable)
 Enables an additional logging output window by means of itk::outputwindow This might be relevant for showing log output in applications with no default output console. More...
 
static void CatchLogFileCommandLineParameter (int &argc, char **argv)
 Automatically extracts and removes the "--logfile <file>" parameters from the standard C main(argc,argv) parameter list and calls SetLogFile if needed. More...
 

Static Protected Member Functions

static bool CheckIfFileExists (const std::string &filename)
 

Additional Inherited Members

- Protected Member Functions inherited from mbilog::TextBackendBase
void FormatSmart (const LogMessage &l, int threadID=0)
 Method formats the given LogMessage in the smart/short format and writes it to std::cout. More...
 
void FormatFull (const LogMessage &l, int threadID=0)
 Method formats the given LogMessage in the full/long format and writes it to std::cout. More...
 
void FormatSmart (std::ostream &out, const LogMessage &l, int threadID=0)
 Method formats the given LogMessage in the smart/short format and writes it to the given std::ostream. More...
 
void FormatFull (std::ostream &out, const LogMessage &l, int threadID=0)
 Method formats the given LogMessage in the full/long format and writes it to the given std::ostream. More...
 
void AppendTimeStamp (std::ostream &out)
 Writes the system time to the given stream. More...
 
void FormatSmartWindows (const mbilog::LogMessage &l, int)
 Special variant of method FormatSmart which uses colored messages (only for windows). More...
 

Detailed Description

mbilog backend implementation for mitk

Definition at line 24 of file mitkLog.h.

Member Function Documentation

◆ CatchLogFileCommandLineParameter()

void mitk::LoggingBackend::CatchLogFileCommandLineParameter ( int &  argc,
char **  argv 
)
static

Automatically extracts and removes the "--logfile <file>" parameters from the standard C main(argc,argv) parameter list and calls SetLogFile if needed.

Definition at line 146 of file mitkLog.cpp.

References MITK_ERROR, and SetLogFile().

◆ CheckIfFileExists()

bool mitk::LoggingBackend::CheckIfFileExists ( const std::string &  filename)
staticprotected

Checks if a file exists.

Returns
Returns true if the file exists, false if not.

Definition at line 230 of file mitkLog.cpp.

References File.

Referenced by IncrementLogFileNames().

◆ EnableAdditionalConsoleWindow()

void mitk::LoggingBackend::EnableAdditionalConsoleWindow ( bool  enable)
static

Enables an additional logging output window by means of itk::outputwindow This might be relevant for showing log output in applications with no default output console.

Definition at line 31 of file mitkLog.cpp.

References logOutputWindow.

◆ GetLogFile()

std::string mitk::LoggingBackend::GetLogFile ( )
static
Returns
Returns the log file if there is one. Returns an empty string if no log file is active.

Definition at line 141 of file mitkLog.cpp.

References logFileName.

◆ GetOutputType()

mbilog::OutputType mitk::LoggingBackend::GetOutputType ( ) const
overridevirtual
Returns
The type of this backend.

Implements mbilog::BackendBase.

Definition at line 246 of file mitkLog.cpp.

References Console.

◆ IncrementLogFileNames()

std::string mitk::LoggingBackend::IncrementLogFileNames ( const std::string &  prefixPath,
int  numLogFiles = 10 
)
static

Increments the names of logfiles with the given prefixPath. This means, if the prefixPath is "myLogFile" myLogFile-0.log is renamed to myLogFile-1.log, myLogFile-1.log to myLogFile-2.log, and so on. The oldest logfile is deleted. The number of log files is defined by the parameter "numLogFiles". The first logfile name is "free" (e.g., [prefix]-0.log) again. This name is retured.

Parameters
prefixPathShould hold the prefix of the logfile together with its path. E.g., "C:/programs/mitk/myLogFile".
numLogFilesSets the number of logfiles. Default value is 10. This means logfiles from [prefix]-0.log to [prefix]-1.log are stored.
Returns
Returns a new logfile name which is free again because the old first log file was renamed.
Exceptions
mitk::ExceptionThrows an exception if there is a problem with renaming the logfiles, e.g., because of file access problems.

Definition at line 184 of file mitkLog.cpp.

References CheckIfFileExists(), and mitkThrow.

Referenced by RotateLogFiles().

◆ ProcessMessage()

void mitk::LoggingBackend::ProcessMessage ( const mbilog::LogMessage l)
overridevirtual

overloaded method for receiving log message from mbilog

Implements mbilog::TextBackendBase.

Definition at line 36 of file mitkLog.cpp.

References mbilog::TextBackendBase::FormatFull(), mbilog::TextBackendBase::FormatSmart(), logFile, logMutex, logOutputWindow, and outputWindow.

◆ Register()

void mitk::LoggingBackend::Register ( )
static

registers MITK logging backend at mbilog

Definition at line 71 of file mitkLog.cpp.

References mbilog::RegisterBackend().

Referenced by main().

◆ RotateLogFiles()

void mitk::LoggingBackend::RotateLogFiles ( const std::string &  prefixPath)
static

Activates and handles a rolling log file with the given prefix and path. This method handles 10 log files with a given prefix, e.g. "myLogFile". The 10 log files will then look like this: myLogFile-0.log (current file) myLogFile-1.log (last file) myLogFile-2.log [...] myLogFile-9.log.

Everytime this method this called, normally when MITK is started, then all log files are copied one file below (0 to 1, 1 to 2, and so on). The oldes logfile (number 9) is always deleted. So users have access to the log files of the last 10 runs.

Exceptions
mitk::ExceptionThrows an exception if there is a problem with renaming the logfiles, e.g., because of file access problems.
Parameters
prefixPathShould hold the prefix of the logfile together with its path. E.g., "C:/programs/mitk/myLogFile".

Definition at line 172 of file mitkLog.cpp.

References IncrementLogFileNames(), and SetLogFile().

◆ SetLogFile()

void mitk::LoggingBackend::SetLogFile ( const char *  file)
static

Sets extra log file path (additionally to the console log)

Definition at line 90 of file mitkLog.cpp.

References logFile, logFileName, logMutex, MITK_INFO, and MITK_WARN.

Referenced by CatchLogFileCommandLineParameter(), RotateLogFiles(), TestThreadSaveLog(), and Unregister().

◆ Unregister()

void mitk::LoggingBackend::Unregister ( )
static

Unregisters MITK logging backend at mbilog.

Definition at line 79 of file mitkLog.cpp.

References mitkLogBackend, SetLogFile(), and mbilog::UnregisterBackend().

Referenced by main().


The documentation for this class was generated from the following files: