mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Overhauling the internal reporting of messages to the user.
The Logger class is now in charge of reporting all errors, warnings, informational messages, weirds, and syslogs. All other components route their messages through the global bro_logger singleton. The Logger class comes with these reporting methods: void Message(const char* fmt, ...); void Warning(const char* fmt, ...); void Error(const char* fmt, ...); void FatalError(const char* fmt, ...); // Terminate Bro. void Weird(const char* name); [ .. some more Weird() variants ... ] void Syslog(const char* fmt, ...); void InternalWarning(const char* fmt, ...); void InternalError(const char* fmt, ...); // Terminates Bro. See Logger.h for more information on these. Generally, the reporting now works as follows: - All non-fatal message are reported in one of two ways: (1) At startup (i.e., before we start processing packets), they are logged to stderr. (2) During processing, they turn into events: event log_message%(msg: string, location: string%); event log_warning%(msg: string, location: string%); event log_error%(msg: string, location: string%); The script level can then handle them as desired. If we don't have an event handler, we fall back to reporting on stderr. - All fatal errors are logged to stderr and Bro terminates immediately. - Syslog(msg) directly syslogs, but doesn't do anything else. The three main types of messages can also be generated on the scripting layer via new Log::* bifs: Log::error(msg: string); Log::warning(msg: string); Log::message(msg: string); These pass through the bro_logger as well and thus are handled in the same way. Their output includes location information. More changes: - Removed the alarm statement and the alarm_hook event. - Adapted lots of locations to use the bro_logger, including some of the messages that were previously either just written to stdout, or even funneled through the alarm mechanism. - No distinction anymore between Error() and RunTime(). There's now only one class of errors; the line was quite blurred already anyway. - util.h: all the error()/warn()/message()/run_time()/pinpoint() functions are gone. Use the bro_logger instead now. - Script errors are formatted a bit differently due to the changes. What I've seen so far looks ok to me, but let me know if there's something odd. Notes: - The default handlers for the new log_* events are just dummy implementations for now since we need to integrate all this into the new scripts anyway. - I'm not too happy with the names of the Logger class and its instance bro_logger. We now have a LogMgr as well, which makes this all a bit confusing. But I didn't have a good idea for better names so I stuck with them for now. Perhaps we should merge Logger and LogMgr?
This commit is contained in:
parent
ff7b92ffc8
commit
93894eed9b
140 changed files with 2453 additions and 1054 deletions
44
src/Val.cc
44
src/Val.cc
|
@ -253,7 +253,7 @@ bool Val::DoSerialize(SerialInfo* info) const
|
|||
return false;
|
||||
}
|
||||
|
||||
internal_error("should not be reached");
|
||||
bro_logger->InternalError("should not be reached");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,7 @@ bool Val::DoUnserialize(UnserialInfo* info)
|
|||
return false;
|
||||
}
|
||||
|
||||
internal_error("should not be reached");
|
||||
bro_logger->InternalError("should not be reached");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -616,7 +616,7 @@ void Val::ValDescribe(ODesc* d) const
|
|||
|
||||
default:
|
||||
// Don't call Internal(), that'll loop!
|
||||
internal_error("Val description unavailable");
|
||||
bro_logger->InternalError("Val description unavailable");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -964,7 +964,7 @@ AddrVal::AddrVal(const char* text) : Val(TYPE_ADDR)
|
|||
#ifdef BROv6
|
||||
Init(dotted_to_addr6(text));
|
||||
#else
|
||||
error("bro wasn't compiled with IPv6 support");
|
||||
bro_logger->Error("bro wasn't compiled with IPv6 support");
|
||||
Init(uint32(0));
|
||||
#endif
|
||||
}
|
||||
|
@ -998,7 +998,7 @@ Val* AddrVal::SizeVal() const
|
|||
#ifdef BROv6
|
||||
if ( ! is_v4_addr(val.addr_val) )
|
||||
{
|
||||
RunTime("|addr| for IPv6 addresses not supported");
|
||||
Error("|addr| for IPv6 addresses not supported");
|
||||
return new Val(0, TYPE_COUNT);
|
||||
}
|
||||
|
||||
|
@ -1085,13 +1085,13 @@ static uint32 parse_dotted(const char* text, int& dots)
|
|||
}
|
||||
|
||||
else
|
||||
internal_error("scanf failed in parse_dotted()");
|
||||
bro_logger->InternalError("scanf failed in parse_dotted()");
|
||||
|
||||
for ( int i = 0; i <= dots; ++i )
|
||||
{
|
||||
if ( addr[i] < 0 || addr[i] > 255 )
|
||||
{
|
||||
error("bad dotted address", text);
|
||||
bro_logger->Error("bad dotted address", text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1105,7 +1105,7 @@ NetVal::NetVal(const char* text) : AddrVal(TYPE_NET)
|
|||
uint32 a = parse_dotted(text, dots);
|
||||
|
||||
if ( addr_to_net(a) != a )
|
||||
error("bad net address", text);
|
||||
bro_logger->Error("bad net address", text);
|
||||
|
||||
Init(uint32(htonl(a)));
|
||||
}
|
||||
|
@ -1129,7 +1129,7 @@ Val* NetVal::SizeVal() const
|
|||
#ifdef BROv6
|
||||
if ( ! is_v4_addr(val.addr_val) )
|
||||
{
|
||||
RunTime("|net| for IPv6 addresses not supported");
|
||||
Error("|net| for IPv6 addresses not supported");
|
||||
return new Val(0.0, TYPE_DOUBLE);
|
||||
}
|
||||
|
||||
|
@ -1998,7 +1998,7 @@ int TableVal::ExpandAndInit(Val* index, Val* new_val)
|
|||
if ( iv->BaseTag() != TYPE_ANY )
|
||||
{
|
||||
if ( table_type->Indices()->Types()->length() != 1 )
|
||||
internal_error("bad singleton list index");
|
||||
bro_logger->InternalError("bad singleton list index");
|
||||
|
||||
for ( int i = 0; i < iv->Length(); ++i )
|
||||
if ( ! ExpandAndInit(iv->Index(i), new_val ? new_val->Ref() : 0) )
|
||||
|
@ -2062,7 +2062,7 @@ Val* TableVal::Default(Val* index)
|
|||
|
||||
if ( ! def_val )
|
||||
{
|
||||
RunTime("non-constant default attribute");
|
||||
Error("non-constant default attribute");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2087,7 +2087,7 @@ Val* TableVal::Default(Val* index)
|
|||
|
||||
if ( ! result )
|
||||
{
|
||||
RunTime("no value returned from &default function");
|
||||
Error("no value returned from &default function");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2193,7 +2193,7 @@ Val* TableVal::Delete(const Val* index)
|
|||
Val* va = v ? (v->Value() ? v->Value() : this->Ref()) : 0;
|
||||
|
||||
if ( subnets && ! subnets->Remove(index) )
|
||||
internal_error( "index not in prefix table" );
|
||||
bro_logger->InternalError( "index not in prefix table" );
|
||||
|
||||
if ( LoggingAccess() )
|
||||
{
|
||||
|
@ -2235,7 +2235,7 @@ Val* TableVal::Delete(const HashKey* k)
|
|||
{
|
||||
Val* index = table_hash->RecoverVals(k);
|
||||
if ( ! subnets->Remove(index) )
|
||||
internal_error( "index not in prefix table" );
|
||||
bro_logger->InternalError( "index not in prefix table" );
|
||||
Unref(index);
|
||||
}
|
||||
|
||||
|
@ -2316,7 +2316,7 @@ void TableVal::Describe(ODesc* d) const
|
|||
TableEntryVal* v = tbl->NextEntry(k, c);
|
||||
|
||||
if ( ! v )
|
||||
internal_error("hash table underflow in TableVal::Describe");
|
||||
bro_logger->InternalError("hash table underflow in TableVal::Describe");
|
||||
|
||||
ListVal* vl = table_hash->RecoverVals(k);
|
||||
int dim = vl->Length();
|
||||
|
@ -2367,7 +2367,7 @@ void TableVal::Describe(ODesc* d) const
|
|||
}
|
||||
|
||||
if ( tbl->NextEntry(c) )
|
||||
internal_error("hash table overflow in TableVal::Describe");
|
||||
bro_logger->InternalError("hash table overflow in TableVal::Describe");
|
||||
|
||||
if ( d->IsPortable() || d->IsReadable() )
|
||||
{
|
||||
|
@ -2489,7 +2489,7 @@ void TableVal::DoExpire(double t)
|
|||
{
|
||||
Val* index = RecoverIndex(k);
|
||||
if ( ! subnets->Remove(index) )
|
||||
internal_error( "index not in prefix table" );
|
||||
bro_logger->InternalError( "index not in prefix table" );
|
||||
Unref(index);
|
||||
}
|
||||
|
||||
|
@ -2610,7 +2610,7 @@ bool TableVal::DoSerialize(SerialInfo* info) const
|
|||
state = (State*) info->cont.RestoreState();
|
||||
}
|
||||
else
|
||||
internal_error("unknown continuation state");
|
||||
bro_logger->InternalError("unknown continuation state");
|
||||
|
||||
HashKey* k;
|
||||
int count = 0;
|
||||
|
@ -2695,7 +2695,7 @@ bool TableVal::DoSerialize(SerialInfo* info) const
|
|||
{
|
||||
info->cont.SaveState(state);
|
||||
info->cont.Suspend();
|
||||
bro_logger->Log("TableVals serialization suspended right in the middle.");
|
||||
bro_logger->Message("TableVals serialization suspended right in the middle.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -3489,7 +3489,7 @@ Val* check_and_promote(Val* v, const BroType* t, int is_init)
|
|||
break;
|
||||
|
||||
default:
|
||||
internal_error("bad internal type in check_and_promote()");
|
||||
bro_logger->InternalError("bad internal type in check_and_promote()");
|
||||
Unref(v);
|
||||
return 0;
|
||||
}
|
||||
|
@ -3500,7 +3500,7 @@ Val* check_and_promote(Val* v, const BroType* t, int is_init)
|
|||
|
||||
int same_val(const Val* /* v1 */, const Val* /* v2 */)
|
||||
{
|
||||
internal_error("same_val not implemented");
|
||||
bro_logger->InternalError("same_val not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3551,7 +3551,7 @@ int same_atomic_val(const Val* v1, const Val* v2)
|
|||
return subnet_eq(v1->AsSubNet(), v2->AsSubNet());
|
||||
|
||||
default:
|
||||
internal_error("same_atomic_val called for non-atomic value");
|
||||
bro_logger->InternalError("same_atomic_val called for non-atomic value");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue