Hui Lin_Can I control when to create logging files

Hi,

In the Bro documentation from the web site, I refer the “Customizing Bro’s Logging” to write my own logs. I pretty under how to customize what to log but I am still confusing on whether I can control to create logging files. The following scripts is shown:

event connection_state_remove(c: connection)
    {
    if ( c$id$orig_h in Site::private_address_space )
        c$conn$is_private = T;
    }

Hope that I make myself clear.

Best,

Hui

From my understanding, it seems that Logs files can only be created whenever connection_state_remove event handler is called.

Specifically for the conn.log, that is the event handler in which the log file entries are written with Log::write(). You can look at where that's done in base/protocols/conn/main.bro.

For other logs, Log::write() may get called from other event handlers depending on what the log file is supposed to convey. E.g. in base/protocols/http/main.bro, you'll see that Log::write() can get called as soon as an HTTP response body is seen, it doesn't wait for the connection_state_remove event, but it does use it as a fallback for writing out incomplete request/response pairs.

I can only customize what to update here. If I don't update it, log files are still created with default values. Is there any way that I can control when to put values in memory into the log files?

In the case you are extending an existing logging stream, you can update your new logging state (record fields marked with &log) in any event handler that you expect to occur before the handlers that do Log::write().

In the case you are designing your own custom logging stream, you get full control over which event handlers you want to update your logging state and which ones you want to write to your log stream. For an example see: http://www.bro-ids.org/documentation/logging.html#adding-streams

+Jon

That really helps.

I am reading former part of the web site and I did not see any thing mentions how logs are written into files. So perhaps it is better to add some of such comment on how logs are written in the section such as “extending log” or generate log framework at the very beginning? And refer to the reader to the customize log stream in the later section. Just for the lazy person like me.