mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
Include file information in input reader error messages
This commit is contained in:
parent
8184073ef8
commit
098a5d3348
13 changed files with 179 additions and 57 deletions
|
@ -5,6 +5,8 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "zeek/DebugLogger.h"
|
||||
#include "zeek/Desc.h"
|
||||
#include "zeek/Obj.h"
|
||||
#include "zeek/RunState.h"
|
||||
#include "zeek/iosource/Manager.h"
|
||||
#include "zeek/threading/Manager.h"
|
||||
|
@ -341,38 +343,105 @@ void MsgThread::Finished()
|
|||
|
||||
void MsgThread::Info(const char* msg)
|
||||
{
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::INFO, this, msg));
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::INFO, this, desc.Description()));
|
||||
}
|
||||
|
||||
void MsgThread::Warning(const char* msg)
|
||||
{
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::WARNING, this, msg));
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(
|
||||
new detail::ReporterMessage(detail::ReporterMessage::WARNING, this, desc.Description()));
|
||||
}
|
||||
|
||||
void MsgThread::Error(const char* msg)
|
||||
{
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::ERROR, this, msg));
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::ERROR, this, desc.Description()));
|
||||
}
|
||||
|
||||
void MsgThread::FatalError(const char* msg)
|
||||
{
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::FATAL_ERROR, this, msg));
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::FATAL_ERROR, this,
|
||||
desc.Description()));
|
||||
}
|
||||
|
||||
void MsgThread::FatalErrorWithCore(const char* msg)
|
||||
{
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::FATAL_ERROR_WITH_CORE, this, msg));
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::FATAL_ERROR_WITH_CORE, this,
|
||||
desc.Description()));
|
||||
}
|
||||
|
||||
void MsgThread::InternalWarning(const char* msg)
|
||||
{
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::INTERNAL_WARNING, this, msg));
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::INTERNAL_WARNING, this,
|
||||
desc.Description()));
|
||||
}
|
||||
|
||||
void MsgThread::InternalError(const char* msg)
|
||||
{
|
||||
// This one aborts immediately.
|
||||
fprintf(stderr, "internal error in thread: %s\n", msg);
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
fprintf(stderr, "internal error in thread: %s\n", desc.Description());
|
||||
abort();
|
||||
}
|
||||
|
||||
|
@ -380,7 +449,16 @@ void MsgThread::InternalError(const char* msg)
|
|||
|
||||
void MsgThread::Debug(DebugStream stream, const char* msg)
|
||||
{
|
||||
SendOut(new detail::DebugMessage(stream, this, msg));
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::DebugMessage(stream, this, desc.Description()));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
#include "zeek/threading/BasicThread.h"
|
||||
#include "zeek/threading/Queue.h"
|
||||
|
||||
namespace zeek::detail
|
||||
{
|
||||
class Location;
|
||||
}
|
||||
|
||||
namespace zeek::threading
|
||||
{
|
||||
|
||||
|
@ -275,6 +280,17 @@ protected:
|
|||
void OnSignalStop() override;
|
||||
void OnKill() override;
|
||||
|
||||
/**
|
||||
* Method for child classes to override to provide file location
|
||||
* information in log messages. This is primarily used by the input
|
||||
* framework's ReaderBackend classes to give more descriptive error
|
||||
* messages.
|
||||
*
|
||||
* @return A Location pointer containing the file location information,
|
||||
* or nullptr if nothing is available.
|
||||
*/
|
||||
virtual zeek::detail::Location* GetLocationInfo() const { return nullptr; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Pops a message sent by the main thread from the main-to-chold
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue