mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 08:38:20 +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
62
src/Net.cc
62
src/Net.cc
|
@ -108,15 +108,6 @@ RETSIGTYPE watchdog(int /* signo */)
|
|||
int frac_pst =
|
||||
int((processing_start_time - int_pst) * 1e6);
|
||||
|
||||
char msg[512];
|
||||
safe_snprintf(msg, sizeof(msg),
|
||||
"**watchdog timer expired, t = %d.%06d, start = %d.%06d, dispatched = %d",
|
||||
int_ct, frac_ct, int_pst, frac_pst,
|
||||
current_dispatched);
|
||||
|
||||
bro_logger->Log(msg);
|
||||
run_time("watchdog timer expired");
|
||||
|
||||
if ( current_hdr )
|
||||
{
|
||||
if ( ! pkt_dumper )
|
||||
|
@ -128,7 +119,7 @@ RETSIGTYPE watchdog(int /* signo */)
|
|||
pkt_dumper = new PktDumper("watchdog-pkt.pcap");
|
||||
if ( pkt_dumper->IsError() )
|
||||
{
|
||||
fprintf(stderr, "watchdog: can't open watchdog-pkt.pcap for writing\n");
|
||||
bro_logger->Error("watchdog: can't open watchdog-pkt.pcap for writing\n");
|
||||
pkt_dumper = 0;
|
||||
}
|
||||
}
|
||||
|
@ -140,8 +131,10 @@ RETSIGTYPE watchdog(int /* signo */)
|
|||
net_get_final_stats();
|
||||
net_finish(0);
|
||||
|
||||
abort();
|
||||
exit(1);
|
||||
bro_logger->FatalErrorWithCore(
|
||||
"**watchdog timer expired, t = %d.%06d, start = %d.%06d, dispatched = %d",
|
||||
int_ct, frac_ct, int_pst, frac_pst,
|
||||
current_dispatched);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,11 +161,8 @@ void net_init(name_list& interfaces, name_list& readfiles,
|
|||
PktFileSrc* ps = new PktFileSrc(readfiles[i], filter);
|
||||
|
||||
if ( ! ps->IsOpen() )
|
||||
{
|
||||
fprintf(stderr, "%s: problem with trace file %s - %s\n",
|
||||
bro_logger->FatalError("%s: problem with trace file %s - %s\n",
|
||||
prog, readfiles[i], ps->ErrorMsg());
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
pkt_srcs.append(ps);
|
||||
|
@ -188,12 +178,9 @@ void net_init(name_list& interfaces, name_list& readfiles,
|
|||
TYPE_FILTER_SECONDARY);
|
||||
|
||||
if ( ! ps->IsOpen() )
|
||||
{
|
||||
fprintf(stderr, "%s: problem with trace file %s - %s\n",
|
||||
bro_logger->FatalError("%s: problem with trace file %s - %s\n",
|
||||
prog, readfiles[i],
|
||||
ps->ErrorMsg());
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
pkt_srcs.append(ps);
|
||||
|
@ -209,11 +196,8 @@ void net_init(name_list& interfaces, name_list& readfiles,
|
|||
FlowFileSrc* fs = new FlowFileSrc(flowfiles[i]);
|
||||
|
||||
if ( ! fs->IsOpen() )
|
||||
{
|
||||
fprintf(stderr, "%s: problem with netflow file %s - %s\n",
|
||||
bro_logger->FatalError("%s: problem with netflow file %s - %s\n",
|
||||
prog, flowfiles[i], fs->ErrorMsg());
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
io_sources.Register(fs);
|
||||
|
@ -232,11 +216,8 @@ void net_init(name_list& interfaces, name_list& readfiles,
|
|||
ps = new PktInterfaceSrc(interfaces[i], filter);
|
||||
|
||||
if ( ! ps->IsOpen() )
|
||||
{
|
||||
fprintf(stderr, "%s: problem with interface %s - %s\n",
|
||||
bro_logger->FatalError("%s: problem with interface %s - %s\n",
|
||||
prog, interfaces[i], ps->ErrorMsg());
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
pkt_srcs.append(ps);
|
||||
|
@ -250,12 +231,9 @@ void net_init(name_list& interfaces, name_list& readfiles,
|
|||
filter, TYPE_FILTER_SECONDARY);
|
||||
|
||||
if ( ! ps->IsOpen() )
|
||||
{
|
||||
fprintf(stderr, "%s: problem with interface %s - %s\n",
|
||||
bro_logger->Error("%s: problem with interface %s - %s\n",
|
||||
prog, interfaces[i],
|
||||
ps->ErrorMsg());
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
pkt_srcs.append(ps);
|
||||
|
@ -271,11 +249,8 @@ void net_init(name_list& interfaces, name_list& readfiles,
|
|||
FlowSocketSrc* fs = new FlowSocketSrc(netflows[i]);
|
||||
|
||||
if ( ! fs->IsOpen() )
|
||||
{
|
||||
fprintf(stderr, "%s: problem with netflow socket %s - %s\n",
|
||||
bro_logger->Error("%s: problem with netflow socket %s - %s\n",
|
||||
prog, netflows[i], fs->ErrorMsg());
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
io_sources.Register(fs);
|
||||
|
@ -297,15 +272,12 @@ void net_init(name_list& interfaces, name_list& readfiles,
|
|||
// interfaces with different-lengthed media.
|
||||
pkt_dumper = new PktDumper(writefile);
|
||||
if ( pkt_dumper->IsError() )
|
||||
{
|
||||
fprintf(stderr, "%s: can't open write file \"%s\" - %s\n",
|
||||
bro_logger->FatalError("%s: can't open write file \"%s\" - %s\n",
|
||||
prog, writefile, pkt_dumper->ErrorMsg());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ID* id = global_scope()->Lookup("trace_output_file");
|
||||
if ( ! id )
|
||||
run_time("trace_output_file not defined in bro.init");
|
||||
bro_logger->Error("trace_output_file not defined in bro.init");
|
||||
else
|
||||
id->SetVal(new StringVal(writefile));
|
||||
}
|
||||
|
@ -565,7 +537,7 @@ void net_get_final_stats()
|
|||
{
|
||||
struct PktSrc::Stats s;
|
||||
ps->Statistics(&s);
|
||||
fprintf(stderr, "%d packets received on interface %s, %d dropped\n",
|
||||
bro_logger->Message("%d packets received on interface %s, %d dropped\n",
|
||||
s.received, ps->Interface(), s.dropped);
|
||||
}
|
||||
}
|
||||
|
@ -588,8 +560,6 @@ void net_finish(int drain_events)
|
|||
|
||||
delete pkt_dumper;
|
||||
|
||||
// fprintf(stderr, "uhash: %d/%d\n", hash_cnt_uhash, hash_cnt_all);
|
||||
|
||||
#ifdef DEBUG
|
||||
extern int reassem_seen_bytes, reassem_copied_bytes;
|
||||
// DEBUG_MSG("Reassembly (TCP and IP/Frag): %d bytes seen, %d bytes copied\n",
|
||||
|
@ -641,7 +611,7 @@ static double suspend_start = 0;
|
|||
void net_suspend_processing()
|
||||
{
|
||||
if ( _processing_suspended == 0 )
|
||||
bro_logger->Log("processing suspended");
|
||||
bro_logger->Message("processing suspended");
|
||||
|
||||
++_processing_suspended;
|
||||
}
|
||||
|
@ -650,7 +620,7 @@ void net_continue_processing()
|
|||
{
|
||||
if ( _processing_suspended == 1 )
|
||||
{
|
||||
bro_logger->Log("processing continued");
|
||||
bro_logger->Message("processing continued");
|
||||
loop_over_list(pkt_srcs, i)
|
||||
pkt_srcs[i]->ContinueAfterSuspend();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue