ug4
ug::LogAssistant Class Reference

#include <log.h>

Public Member Functions

std::ostream & debug_logger ()
 returns the debug output stream More...
 
bool enable_file_output (bool bEnable, const char *filename="uglog.log")
 enables or disables file output. More...
 
bool enable_terminal_output (bool bEnable)
 enables or disables terminal output. More...
 
std::ostream & error_logger ()
 returns the error output stream More...
 
void flush ()
 
void flush_error_log ()
 outputs all gathered error-logs to the standard logger and clears the error log. More...
 
int get_debug_level (const char *debugID) const
 returns the debug level of debugID More...
 
int get_debug_level (DebugID &debugID) const
 returns the debug level of debugID More...
 
int get_debug_level_noninline (const char *debugID) const
 returns the debug level of debugID More...
 
int get_output_process ()
 returns the rank of the current output-process or -1 if all procs perform output. More...
 
int get_process_rank ()
 returns the process rank of the underlying process (same as pcl::ProcRank) More...
 
std::string get_registered_debug_IDs ()
 returns the debug level of debugID More...
 
bool is_output_process ()
 returns true if the current process is an output process. More...
 
std::ostream & logger ()
 returns the normal output stream More...
 
bool rename_log_file (const char *newname)
 renames output file if opened. More...
 
bool set_debug_level (const char *debugID, int level)
 returns the debug level of debugID More...
 
bool set_debug_level (DebugID &debugID, int level)
 sets the debug level of debugID More...
 
bool set_debug_level_noninline (const char *debugID, int level)
 
bool set_debug_levels (int lev)
 sets the debug level of all tags to 'lev' More...
 
void set_output_process (int procRank)
 sets the output-process in a parallel environment. Default is 0. More...
 
 ~LogAssistant ()
 flushes all buffers before deletion More...
 

Static Public Member Functions

static LogAssistantinstance ()
 returns a reference to the single instance of LogAssistant More...
 

Protected Member Functions

bool open_logfile ()
 opens the local logFile, if the process is the output-process More...
 
void update_ostream ()
 updates and sets stream buffers based on current options. More...
 

Private Member Functions

void init ()
 Performs some initialization. More...
 
 LogAssistant ()
 Constructor, resets all debug levels to -1. More...
 
 LogAssistant (const LogAssistant &)
 Prevent copying through private copy constructor. More...
 

Private Attributes

std::streambuf * m_emptyBuf
 
EmptyStreamBuffer m_emptyBufInst
 
std::stringstream m_errStream
 
std::streambuf * m_fileBuf
 
bool m_fileOutputEnabled
 
std::ofstream m_fileStream
 
std::streambuf * m_logBuf
 
std::string m_logFileName
 
int m_outputProc
 
std::streambuf * m_splitBuf
 
OStreamBufferSplitter m_splitBufInst
 
bool m_terminalOutputEnabled
 

Detailed Description

This class provides infrastructure for logging. It separates the log messages in different levels:

logger() returns the output stream for normal User information output. debug_logger() returns the output stream for debug informations.

Debug messages are grouped by tags and debug levels. It is intended, that only messages are printed, when the current level is equal or greater than the debug level chosen in the code.

Please note that this class operates on std::clog. Thus, if output-options are changed (e.g. file-logging enabled) the stream buffer on which clog operates will change too.

Constructor & Destructor Documentation

◆ ~LogAssistant()

ug::LogAssistant::~LogAssistant ( )

flushes all buffers before deletion

References flush(), and m_fileStream.

◆ LogAssistant() [1/2]

ug::LogAssistant::LogAssistant ( )
private

Constructor, resets all debug levels to -1.

Constructor is private since only one instance of LogAssistant may exist.

◆ LogAssistant() [2/2]

ug::LogAssistant::LogAssistant ( const LogAssistant )
private

Prevent copying through private copy constructor.

Member Function Documentation

◆ debug_logger()

std::ostream & ug::LogAssistant::debug_logger ( )
inline

returns the debug output stream

◆ enable_file_output()

bool ug::LogAssistant::enable_file_output ( bool  bEnable,
const char *  filename = "uglog.log" 
)

enables or disables file output.

a filename can be specified. Default is 'uglog.log'. Please note that only the filename given at the first call is considered. Filelogging is disabled by default.

References m_fileOutputEnabled, m_fileStream, m_logFileName, open_logfile(), PROFILE_FUNC, and update_ostream().

Referenced by ugshell_main().

◆ enable_terminal_output()

bool ug::LogAssistant::enable_terminal_output ( bool  bEnable)

enables or disables terminal output.

terminal output is enbled by default.

References m_terminalOutputEnabled, PROFILE_FUNC, and update_ostream().

Referenced by ugshell_main().

◆ error_logger()

std::ostream & ug::LogAssistant::error_logger ( )
inline

returns the error output stream

Note that error-logs are not immediately visible. Instead they are gathered and can be printed in one block using LogAssistant::flush_error_log().

References m_errStream.

◆ flush()

◆ flush_error_log()

void ug::LogAssistant::flush_error_log ( )

outputs all gathered error-logs to the standard logger and clears the error log.

References logger(), and m_errStream.

Referenced by Java_edu_gcsc_vrl_ug_UG__1ugInit(), ug::vrl::registry2NativeAPI(), and ug::UGFinalizeNoPCLFinalize().

◆ get_debug_level() [1/2]

int ug::LogAssistant::get_debug_level ( const char *  debugID) const
inline

returns the debug level of debugID

References ug::DebugIDManager::get_debug_level(), and ug::GetDebugIDManager().

◆ get_debug_level() [2/2]

int ug::LogAssistant::get_debug_level ( DebugID debugID) const
inline

returns the debug level of debugID

References ug::DebugIDManager::get_debug_level(), and ug::GetDebugIDManager().

◆ get_debug_level_noninline()

int ug::LogAssistant::get_debug_level_noninline ( const char *  debugID) const

returns the debug level of debugID

References ug::DebugIDManager::get_debug_level(), and ug::GetDebugIDManager().

◆ get_output_process()

int ug::LogAssistant::get_output_process ( )
inline

returns the rank of the current output-process or -1 if all procs perform output.

References m_outputProc.

Referenced by ug::LogIndexLayoutOnAllProcs(), ug::IApproximationSpace::print_layout_statistic(), ug::print_mark(), pcl::SendRecvBuffersMatch(), and pcl::SendRecvListsMatch().

◆ get_process_rank()

int ug::LogAssistant::get_process_rank ( )

returns the process rank of the underlying process (same as pcl::ProcRank)

References pcl::ProcRank().

◆ get_registered_debug_IDs()

std::string ug::LogAssistant::get_registered_debug_IDs ( )
inline

returns the debug level of debugID

References ug::DebugIDManager::get_registered_debug_IDs(), and ug::GetDebugIDManager().

◆ init()

void ug::LogAssistant::init ( )
private

◆ instance()

LogAssistant & ug::LogAssistant::instance ( )
static

returns a reference to the single instance of LogAssistant

References init().

Referenced by ug::GetLogAssistant().

◆ is_output_process()

bool ug::LogAssistant::is_output_process ( )

returns true if the current process is an output process.

This is always true, if the application is executed in a serial environment.

References m_outputProc, and pcl::ProcRank().

Referenced by open_logfile(), update_ostream(), ug::VTKOutput< TDim >::write_pvtu(), ug::VTKOutput< TDim >::write_subset_pvd(), ug::VTKOutput< TDim >::write_time_processwise_pvd(), ug::VTKOutput< TDim >::write_time_pvd(), and ug::VTKOutput< TDim >::write_time_pvd_subset().

◆ logger()

std::ostream & ug::LogAssistant::logger ( )
inline

returns the normal output stream

Referenced by flush(), and flush_error_log().

◆ open_logfile()

bool ug::LogAssistant::open_logfile ( )
protected

opens the local logFile, if the process is the output-process

References is_output_process(), m_fileOutputEnabled, m_fileStream, m_logFileName, PROFILE_FUNC, and UG_LOG.

Referenced by enable_file_output(), and update_ostream().

◆ rename_log_file()

bool ug::LogAssistant::rename_log_file ( const char *  newname)

renames output file if opened.

References flush(), m_fileStream, m_logFileName, PROFILE_FUNC, and UG_LOG.

◆ set_debug_level() [1/2]

bool ug::LogAssistant::set_debug_level ( const char *  debugID,
int  level 
)
inline

returns the debug level of debugID

References ug::GetDebugIDManager(), and ug::DebugIDManager::set_debug_level().

◆ set_debug_level() [2/2]

bool ug::LogAssistant::set_debug_level ( DebugID debugID,
int  level 
)
inline

sets the debug level of debugID

References ug::GetDebugIDManager(), and ug::DebugIDManager::set_debug_level().

Referenced by ug::bridge::SetDebugLevel().

◆ set_debug_level_noninline()

bool ug::LogAssistant::set_debug_level_noninline ( const char *  debugID,
int  level 
)

◆ set_debug_levels()

bool ug::LogAssistant::set_debug_levels ( int  lev)
inline

sets the debug level of all tags to 'lev'

References ug::GetDebugIDManager(), and ug::DebugIDManager::set_debug_levels().

Referenced by init().

◆ set_output_process()

void ug::LogAssistant::set_output_process ( int  procRank)

sets the output-process in a parallel environment. Default is 0.

pass a procRank of -1 to enable output on all processes.

References m_outputProc, pcl::NumProcs(), UG_LOG, and update_ostream().

Referenced by ug::LogIndexLayoutOnAllProcs(), ug::print_mark(), ug::UGInit(), and ugshell_main().

◆ update_ostream()

void ug::LogAssistant::update_ostream ( )
protected

updates and sets stream buffers based on current options.

Note that this method changes the buffer on which clog works.

References is_output_process(), m_emptyBuf, m_fileBuf, m_fileOutputEnabled, m_logBuf, m_splitBuf, m_terminalOutputEnabled, and open_logfile().

Referenced by enable_file_output(), enable_terminal_output(), init(), and set_output_process().

Member Data Documentation

◆ m_emptyBuf

std::streambuf* ug::LogAssistant::m_emptyBuf
private

Referenced by init(), and update_ostream().

◆ m_emptyBufInst

EmptyStreamBuffer ug::LogAssistant::m_emptyBufInst
private

Referenced by init().

◆ m_errStream

std::stringstream ug::LogAssistant::m_errStream
private

Referenced by error_logger(), and flush_error_log().

◆ m_fileBuf

std::streambuf* ug::LogAssistant::m_fileBuf
private

Referenced by init(), and update_ostream().

◆ m_fileOutputEnabled

bool ug::LogAssistant::m_fileOutputEnabled
private

◆ m_fileStream

std::ofstream ug::LogAssistant::m_fileStream
private

◆ m_logBuf

std::streambuf* ug::LogAssistant::m_logBuf
private

Referenced by init(), and update_ostream().

◆ m_logFileName

std::string ug::LogAssistant::m_logFileName
private

◆ m_outputProc

int ug::LogAssistant::m_outputProc
private

◆ m_splitBuf

std::streambuf* ug::LogAssistant::m_splitBuf
private

Referenced by init(), and update_ostream().

◆ m_splitBufInst

OStreamBufferSplitter ug::LogAssistant::m_splitBufInst
private

Referenced by flush(), and init().

◆ m_terminalOutputEnabled

bool ug::LogAssistant::m_terminalOutputEnabled
private

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