mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Move some repetitive code into a separate method
This commit is contained in:
parent
ec50b66ff3
commit
f4461d5e95
3 changed files with 25 additions and 80 deletions
|
@ -89,11 +89,11 @@ public:
|
|||
INTERNAL_ERROR
|
||||
};
|
||||
|
||||
ReporterMessage(Type arg_type, MsgThread* thread, const char* arg_msg)
|
||||
ReporterMessage(Type arg_type, MsgThread* thread, std::string_view arg_msg)
|
||||
: OutputMessage<MsgThread>("ReporterMessage", thread)
|
||||
{
|
||||
type = arg_type;
|
||||
msg = util::copy_string(arg_msg);
|
||||
msg = util::copy_string(arg_msg.data());
|
||||
}
|
||||
|
||||
~ReporterMessage() override { delete[] msg; }
|
||||
|
@ -125,11 +125,11 @@ public:
|
|||
class DebugMessage final : public OutputMessage<MsgThread>
|
||||
{
|
||||
public:
|
||||
DebugMessage(DebugStream arg_stream, MsgThread* thread, const char* arg_msg)
|
||||
DebugMessage(DebugStream arg_stream, MsgThread* thread, std::string_view arg_msg)
|
||||
: OutputMessage<MsgThread>("DebugMessage", thread)
|
||||
{
|
||||
stream = arg_stream;
|
||||
msg = util::copy_string(arg_msg);
|
||||
msg = util::copy_string(arg_msg.data());
|
||||
}
|
||||
|
||||
~DebugMessage() override { delete[] msg; }
|
||||
|
@ -341,7 +341,7 @@ void MsgThread::Finished()
|
|||
SendOut(new detail::FinishedMessage(this));
|
||||
}
|
||||
|
||||
void MsgThread::Info(const char* msg)
|
||||
std::string MsgThread::BuildMsgWithLocation(const char* msg)
|
||||
{
|
||||
ODesc desc;
|
||||
|
||||
|
@ -352,96 +352,48 @@ void MsgThread::Info(const char* msg)
|
|||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::INFO, this, desc.Description()));
|
||||
return std::string(desc.Description());
|
||||
}
|
||||
|
||||
void MsgThread::Info(const char* msg)
|
||||
{
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::INFO, this,
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::Warning(const char* 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()));
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::WARNING, this,
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::Error(const char* 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()));
|
||||
SendOut(new detail::ReporterMessage(detail::ReporterMessage::ERROR, this,
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::FatalError(const char* 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()));
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::FatalErrorWithCore(const char* 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()));
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::InternalWarning(const char* 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()));
|
||||
BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
void MsgThread::InternalError(const char* msg)
|
||||
{
|
||||
// This one aborts immediately.
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
fprintf(stderr, "internal error in thread: %s\n", desc.Description());
|
||||
fprintf(stderr, "internal error in thread: %s\n", BuildMsgWithLocation(msg).c_str());
|
||||
abort();
|
||||
}
|
||||
|
||||
|
@ -449,16 +401,7 @@ void MsgThread::InternalError(const char* msg)
|
|||
|
||||
void MsgThread::Debug(DebugStream stream, const char* msg)
|
||||
{
|
||||
ODesc desc;
|
||||
|
||||
if ( auto* location = GetLocationInfo() )
|
||||
{
|
||||
location->Describe(&desc);
|
||||
desc.Add(": ");
|
||||
}
|
||||
|
||||
desc.Add(msg);
|
||||
SendOut(new detail::DebugMessage(stream, this, desc.Description()));
|
||||
SendOut(new detail::DebugMessage(stream, this, BuildMsgWithLocation(msg)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue