Function logJsonInfo

Logs a message in compressed single-line JSON format.

void logJsonInfo(T...) (
  lazy T args
) nothrow;

Produces a JSON object with the key-value pairs given as args and default fields "thread", "timestamp" and "logLevel".

Example

logJsonInfo(
    "action", "findTheTruth",
    "answer", 42,
    "elapsedSecs", 1337,
);

// --> (real output is compressed in a single line)
// {
//     "action": "findTheTruth",
//     "answer": 42,
//     "elapsedSecs": 1337
//     "thread": 123467890,
//     "timestamp", 123467890
//     "logLevel", "info"
// }

Parameters

NameDescription
args pairs of name (string) and value

Example

import std.stdio : File, stderr;
import vibe.data.json : Json, parseJsonString;

auto origStderr = stderr;
stderr = File.tmpfile();
scope (exit)
{
    stderr.close();
    stderr = origStderr;
}

logJsonError(
    "error", "mysterious observation",
    "secret", 42,
);

stderr.rewind();
auto observed = parseJsonString(stderr.readln);

assert(observed["thread"].type == Json.Type.int_);
assert(observed["timestamp"].type == Json.Type.int_);
assert(observed["error"] == "mysterious observation");
assert(observed["secret"] == 42);