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:
Robin Sommer 2011-06-24 21:33:05 -07:00
parent ff7b92ffc8
commit 93894eed9b
140 changed files with 2453 additions and 1054 deletions

View file

@ -273,7 +273,7 @@ bool LogVal::Read(SerializationFormat* fmt)
}
default:
internal_error("unsupported type %s in LogVal::Write", type_name(type));
bro_logger->InternalError("unsupported type %s in LogVal::Write", type_name(type));
}
return false;
@ -374,7 +374,7 @@ bool LogVal::Write(SerializationFormat* fmt) const
}
default:
internal_error("unsupported type %s in LogVal::REad", type_name(type));
bro_logger->InternalError("unsupported type %s in LogVal::REad", type_name(type));
}
return false;
@ -452,7 +452,7 @@ bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
if ( ! same_type(rtype, BifType::Record::Log::Stream, 0) )
{
run_time("sval argument not of right type");
bro_logger->Error("sval argument not of right type");
return false;
}
@ -468,7 +468,7 @@ bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
if ( ! LogVal::IsCompatibleType(columns->FieldType(i)) )
{
run_time("type of field '%s' is not support for logging output",
bro_logger->Error("type of field '%s' is not support for logging output",
columns->FieldName(i));
return false;
@ -479,7 +479,7 @@ bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
if ( ! log_attr_present )
{
run_time("logged record type does not have any &log attributes");
bro_logger->Error("logged record type does not have any &log attributes");
return false;
}
@ -493,7 +493,7 @@ bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
if ( ! etype->IsEvent() )
{
run_time("stream event is a function, not an event");
bro_logger->Error("stream event is a function, not an event");
return false;
}
@ -501,13 +501,13 @@ bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
if ( args->length() != 1 )
{
run_time("stream event must take a single argument");
bro_logger->Error("stream event must take a single argument");
return false;
}
if ( ! same_type((*args)[0], columns) )
{
run_time("stream event's argument type does not match column record type");
bro_logger->Error("stream event's argument type does not match column record type");
return new Val(0, TYPE_BOOL);
}
}
@ -627,7 +627,7 @@ bool LogMgr::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt,
else
{
run_time("unsupported field type for log column");
bro_logger->Error("unsupported field type for log column");
return false;
}
}
@ -666,7 +666,7 @@ bool LogMgr::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt,
if ( ! filter->fields )
{
run_time("out of memory in add_filter");
bro_logger->Error("out of memory in add_filter");
return false;
}
@ -685,7 +685,7 @@ bool LogMgr::AddFilter(EnumVal* id, RecordVal* fval)
if ( ! same_type(rtype, BifType::Record::Log::Filter, 0) )
{
run_time("filter argument not of right type");
bro_logger->Error("filter argument not of right type");
return false;
}
@ -835,7 +835,7 @@ bool LogMgr::Write(EnumVal* id, RecordVal* columns)
if ( ! columns )
{
run_time("incompatible log record type");
bro_logger->Error("incompatible log record type");
return false;
}
@ -877,7 +877,7 @@ bool LogMgr::Write(EnumVal* id, RecordVal* columns)
if ( ! v->Type()->Tag() == TYPE_STRING )
{
run_time("path_func did not return string");
bro_logger->Error("path_func did not return string");
Unref(v);
return false;
}
@ -1061,7 +1061,7 @@ LogVal* LogMgr::ValToLogVal(Val* val, BroType* ty)
}
default:
internal_error("unsupported type for log_write");
bro_logger->InternalError("unsupported type for log_write");
}
return lval;
@ -1126,7 +1126,7 @@ LogWriter* LogMgr::CreateWriter(EnumVal* id, EnumVal* writer, string path,
{
if ( ld->type == BifEnum::Log::WRITER_DEFAULT )
{
run_time("unknow writer when creating writer");
bro_logger->Error("unknow writer when creating writer");
return 0;
}
@ -1285,7 +1285,7 @@ bool LogMgr::Flush(EnumVal* id)
void LogMgr::Error(LogWriter* writer, const char* msg)
{
run_time(fmt("error with writer for %s: %s",
bro_logger->Error(fmt("error with writer for %s: %s",
writer->Path().c_str(), msg));
}