[syslog-ng] [PATCH 0/4]: Template type hinting, request for review

Gergely Nagy algernon at balabit.hu
Fri Feb 15 16:26:01 CET 2013


The patches that will come soon after this one implement template type
hinting support for syslog-ng. These things allow us to tell the
various destination drivers what type a particular template should be
casted to.

One can use this to store dates in MongoDB as datetime objects, or the
PID as integer, and so on and so forth.

The syntax is simple:

 template(type("template-string"))

Where 'type' can be 'boolean', 'string', 'int32', 'int64', 'datetime'
or 'literal' as of this writing. Not all drivers implement all of
them, of course, but they implement the relevant ones.

The infrastructure makes it possible to control what should happen
when a type cast does not succeed: we can either drop the message (the
default), drop that particular property, or fall back to string. We
can do either of these silently, or by emitting a warning first. This
is configurable with a global option only at the moment, but there are
plans to make it possible to override the global setting on a
per-template or per-driver level.

A few examples on usage:

template t_json {
  template("$(format-json PID=int32($PID) MESSAGE DATE)\n")
};

destination d_mongodb {
  mongodb(
    value-pairs(pair("PID", int32("$PID"))
                pair("TIMESTAMP", datetime("$R_UNIXTIME")))
  );
};

I'm reasonably happy with the code, at least for now. I plan to
improve upon it within the scope of 3.5, but this is at a stage that I
consider very close to merge ready.




More information about the syslog-ng mailing list