mirror of https://github.com/Icinga/icinga2.git
parent
4428b8c6ee
commit
64aa5d1b09
|
@ -89,7 +89,7 @@ static bool LoadConfigFiles(const String& appType, ValidationType validate)
|
|||
|
||||
BOOST_FOREACH(const ConfigCompilerMessage& message, ConfigCompilerContext::GetInstance()->GetMessages()) {
|
||||
std::ostringstream locbuf;
|
||||
ShowCodeFragment(locbuf, message.Location);
|
||||
ShowCodeFragment(locbuf, message.Location, true);
|
||||
String location = locbuf.str();
|
||||
|
||||
String logmsg;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "base/utility.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/object.h"
|
||||
#include "base/logger_fwd.h"
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/exception_ptr.hpp>
|
||||
#include <boost/exception/errinfo_nested_exception.hpp>
|
||||
|
@ -45,6 +46,14 @@ AExpression::AExpression(OpCallback op, const Value& operand1, const Value& oper
|
|||
Value AExpression::Evaluate(const Dictionary::Ptr& locals) const
|
||||
{
|
||||
try {
|
||||
#ifdef _DEBUG
|
||||
if (m_Operator != &AExpression::OpLiteral) {
|
||||
std::ostringstream msgbuf;
|
||||
ShowCodeFragment(msgbuf, m_DebugInfo, false);
|
||||
Log(LogDebug, "config", "Executing:\n" + msgbuf.str());
|
||||
}
|
||||
#endif /* _DEBUG */
|
||||
|
||||
return m_Operator(this, locals);
|
||||
} catch (const std::exception& ex) {
|
||||
if (boost::get_error_info<boost::errinfo_nested_exception>(ex))
|
||||
|
|
|
@ -38,6 +38,6 @@ std::string icinga::to_string(const errinfo_debuginfo& e)
|
|||
{
|
||||
std::ostringstream msgbuf;
|
||||
msgbuf << "Config location: " << e.value() << "\n";
|
||||
ShowCodeFragment(msgbuf, e.value());
|
||||
ShowCodeFragment(msgbuf, e.value(), true);
|
||||
return msgbuf.str();
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ DebugInfo icinga::DebugInfoRange(const DebugInfo& start, const DebugInfo& end)
|
|||
|
||||
#define EXTRA_LINES 2
|
||||
|
||||
void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di)
|
||||
void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di, bool verbose)
|
||||
{
|
||||
if (di.Path.IsEmpty())
|
||||
return;
|
||||
|
@ -61,17 +61,23 @@ void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di)
|
|||
std::ifstream ifs;
|
||||
ifs.open(di.Path.CStr(), std::ifstream::in);
|
||||
|
||||
int lineno = 1;
|
||||
int lineno = 0;
|
||||
char line[1024];
|
||||
|
||||
while (ifs.good() && lineno <= di.LastLine + EXTRA_LINES) {
|
||||
lineno++;
|
||||
|
||||
ifs.getline(line, sizeof(line));
|
||||
|
||||
for (int i = 0; line[i]; i++)
|
||||
if (line[i] == '\t')
|
||||
line[i] = ' ';
|
||||
|
||||
if (lineno >= di.FirstLine - EXTRA_LINES && lineno <= di.LastLine + EXTRA_LINES) {
|
||||
int extra_lines = verbose ? EXTRA_LINES : 0;
|
||||
|
||||
if (lineno < di.FirstLine - extra_lines || lineno > di.LastLine + extra_lines)
|
||||
continue;
|
||||
|
||||
String pathInfo = di.Path + "(" + Convert::ToString(lineno) + "): ";
|
||||
out << pathInfo;
|
||||
out << line << "\n";
|
||||
|
@ -95,7 +101,4 @@ void icinga::ShowCodeFragment(std::ostream& out, const DebugInfo& di)
|
|||
out << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
lineno++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ I2_CONFIG_API std::ostream& operator<<(std::ostream& out, const DebugInfo& val);
|
|||
|
||||
I2_CONFIG_API DebugInfo DebugInfoRange(const DebugInfo& start, const DebugInfo& end);
|
||||
|
||||
I2_CONFIG_API void ShowCodeFragment(std::ostream& out, const DebugInfo& di);
|
||||
I2_CONFIG_API void ShowCodeFragment(std::ostream& out, const DebugInfo& di, bool verbose);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue