#include <kaldi-error.h>

Collaboration diagram for MessageLogger:

Classes

struct  Log
 
struct  LogAndThrow
 

Public Member Functions

 MessageLogger (LogMessageEnvelope::Severity severity, const char *func, const char *file, int32 line)
 The constructor stores the message's "envelope", a set of data which. More...
 
template<typename T >
MessageLoggeroperator<< (const T &val)
 

Private Member Functions

std::string GetMessage () const
 
void LogMessage () const
 

Private Attributes

LogMessageEnvelope envelope_
 
std::ostringstream ss_
 

Detailed Description

Definition at line 109 of file kaldi-error.h.

Constructor & Destructor Documentation

◆ MessageLogger()

MessageLogger ( LogMessageEnvelope::Severity  severity,
const char *  func,
const char *  file,
int32  line 
)

The constructor stores the message's "envelope", a set of data which.

Definition at line 174 of file kaldi-error.cc.

References kaldi::GetShortFileName().

175  {
176  // Obviously, we assume the strings survive the destruction of this object.
177  envelope_.severity = severity;
178  envelope_.func = func;
179  envelope_.file = GetShortFileName(file); // Points inside 'file'.
180  envelope_.line = line;
181 }
const char * func
Name of the function invoking the logging.
Definition: kaldi-error.h:81
const char * file
Source file name with up to 1 leading directory.
Definition: kaldi-error.h:82
LogMessageEnvelope envelope_
Definition: kaldi-error.h:142
static const char * GetShortFileName(const char *path)
Definition: kaldi-error.cc:63
int severity
A Severity value, or positive verbosity level.
Definition: kaldi-error.h:80

Member Function Documentation

◆ GetMessage()

std::string GetMessage ( ) const
inlineprivate

Definition at line 139 of file kaldi-error.h.

Referenced by MessageLogger::LogAndThrow::operator=().

139 { return ss_.str(); }
std::ostringstream ss_
Definition: kaldi-error.h:143

◆ LogMessage()

void LogMessage ( ) const
private

Definition at line 183 of file kaldi-error.cc.

References KALDI_VERSION, kaldi::KaldiGetStackTrace(), LogMessageEnvelope::kAssertFailed, LogMessageEnvelope::kError, LogMessageEnvelope::kInfo, LogMessageEnvelope::kWarning, and kaldi::log_handler.

Referenced by MessageLogger::Log::operator=(), and MessageLogger::LogAndThrow::operator=().

183  {
184  // Send to the logging handler if provided.
185  if (log_handler != NULL) {
186  log_handler(envelope_, GetMessage().c_str());
187  return;
188  }
189 
190  // Otherwise, use the default Kaldi logging.
191  // Build the log-message header.
192  std::stringstream full_message;
194  full_message << "VLOG[" << envelope_.severity << "] (";
195  } else {
196  switch (envelope_.severity) {
198  full_message << "LOG (";
199  break;
201  full_message << "WARNING (";
202  break;
204  full_message << "ASSERTION_FAILED (";
205  break;
207  default: // If not the ERROR, it still an error!
208  full_message << "ERROR (";
209  break;
210  }
211  }
212  // Add other info from the envelope and the message text.
213  full_message << program_name.c_str() << "[" KALDI_VERSION "]" << ':'
214  << envelope_.func << "():" << envelope_.file << ':'
215  << envelope_.line << ") " << GetMessage().c_str();
216 
217  // Add stack trace for errors and assertion failures, if available.
219  const std::string &stack_trace = KaldiGetStackTrace();
220  if (!stack_trace.empty()) {
221  full_message << "\n\n" << stack_trace;
222  }
223  }
224 
225  // Print the complete message to stderr.
226  full_message << "\n";
227  std::cerr << full_message.str();
228 }
const char * func
Name of the function invoking the logging.
Definition: kaldi-error.h:81
const char * file
Source file name with up to 1 leading directory.
Definition: kaldi-error.h:82
static std::string program_name
Definition: kaldi-error.cc:47
static std::string KaldiGetStackTrace()
Definition: kaldi-error.cc:133
LogMessageEnvelope envelope_
Definition: kaldi-error.h:142
Informational message.
Definition: kaldi-error.h:78
static LogHandler log_handler
Definition: kaldi-error.cc:48
std::string GetMessage() const
Definition: kaldi-error.h:139
#define KALDI_VERSION
Definition: version.h:3
Fatal error. KaldiFatalError will be thrown.
Definition: kaldi-error.h:76
Assertion failure. abort() will be called.
Definition: kaldi-error.h:75
Indicates a recoverable but abnormal condition.
Definition: kaldi-error.h:77
int severity
A Severity value, or positive verbosity level.
Definition: kaldi-error.h:80

◆ operator<<()

MessageLogger& operator<< ( const T &  val)
inline

Definition at line 119 of file kaldi-error.h.

119  {
120  ss_ << val;
121  return *this;
122  }
std::ostringstream ss_
Definition: kaldi-error.h:143

Member Data Documentation

◆ envelope_

LogMessageEnvelope envelope_
private

Definition at line 142 of file kaldi-error.h.

◆ ss_

std::ostringstream ss_
private

Definition at line 143 of file kaldi-error.h.


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