Skip to content

Commit

Permalink
attributes: Extend &log section a bit
Browse files Browse the repository at this point in the history
Closes #107
  • Loading branch information
awelzel committed Oct 13, 2023
1 parent 3b8ca1d commit 902c504
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion script-reference/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,42 @@ default value is ``0``. Example:
&log
----

Writes a :zeek:type:`record` field to the associated log stream.
When a :zeek:type:`record` field has the ``&log`` attribute, this field is
included as a column in the log stream associated with the record type. This
association happens with :zeek:see:`Log::create_stream` and commonly looks as
follows:

.. code-block:: zeek
redef enum Log::ID += { LOG };
type Info: record {
ts: time &log &default=network_time();
id: conn_id &log;
msg: string &log;
hidden: count &default=0; # This is not logged.
};
event zeek_init() {
Log::create_stream(LOG, [$columns=Info, $path="example"]);
}
The log stream above will have the columns ``ts``, ``id`` and ``msg``.

When ``&log`` is placed at the end of a record type declaration, all fields
listed in the declaration will have the ``&log`` attribute implicitly.

.. code-block:: zeek
type conn_id: record {
orig_h: addr;
orig_p: port;
resp_h: addr;
resp_p: port;
} &log;
Fields added to such a record types later on using :zeek:see:`redef` need to
explicitly specify ``&log`` again, however.

.. zeek:attr:: &optional
Expand Down

0 comments on commit 902c504

Please sign in to comment.