On Tuesday, 15 October 2013 at 15:21:52 UTC, Johannes Pfau wrote:
I think one increasingly important point for std.log is 'structured
logging'.

Structured logging is basically not simply logging textual messages, but also logging additional KEY/VALUE pairs of data. The idea is that logs
should not only be readable by humans but also easy to parse and
analyze. Structured logging often also includes UUIDs to simplify
finding similar errors/problems in a log file.

For example: Instead of logging
logf("Couldn't login as %s on server %s : Reason: %s", user, server,
      errorCode);

we'd do:
log(LOGIN_FAILED_UUID, "Couldn't log in", ["User": user, "Server":
    server, "ErrorCode": errorCode]);

The log can then be queried for all events with 'LOGIN_FAILED_UUID'
uuid, Server="..." ErrorCode=42, etc.

+1
I like the idea of structured logging.
I really need to log some complex data, not only string. I usually use `to!string(value)` to convert complex data to string.

About syntax - we can use something like this:
log!(user, server, errorCode)(LOGIN_FAILED_UUID, "Couldn't log in");

user, server and errorCode is variables passed to template. We can get variable value as usually and variable name via `__traits(identifier, variable)`, it should work after DMD 2.064.

For example, Vide.d use this idea, see `render` function:
http://vibed.org/docs

We can store complex data as string via `to!string(value)` cast until we can use real backend implementation like SystemDs.

Reply via email to