Message

This struct provides a convenient way to create and inspect a GELF message.

Constructors

this
this(string host, string short_message)
Undocumented in source.
this
this(string host, string short_message, Level level)
Undocumented in source.

Members

Functions

fullMessage
auto fullMessage()
Undocumented in source. Be warned that the author may not have intended to support it.
fullMessage
auto fullMessage(string msg)
Undocumented in source. Be warned that the author may not have intended to support it.
level
auto level()
Undocumented in source. Be warned that the author may not have intended to support it.
level
auto level(Level l)
Undocumented in source. Be warned that the author may not have intended to support it.
opDispatch
auto opDispatch(T i)
Undocumented in source. Be warned that the author may not have intended to support it.
opDispatch
string opDispatch()
Undocumented in source. Be warned that the author may not have intended to support it.
opIndexAssign
void opIndexAssign(string key, string value)
Undocumented in source. Be warned that the author may not have intended to support it.
timestamp
auto timestamp(SysTime sysTime)
Undocumented in source. Be warned that the author may not have intended to support it.
timestamp
auto timestamp(size_t timestamp)
Undocumented in source. Be warned that the author may not have intended to support it.
timestamp
auto timestamp(double timestamp)
Undocumented in source. Be warned that the author may not have intended to support it.
toBytes
immutable(ubyte[]) toBytes()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
void toString(Dg sink)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

full_message
string full_message;
Undocumented in source.
host
string host;
Undocumented in source.
short_message
string short_message;
Undocumented in source.

Examples

writeln(Message("localhost","HUGE ERROR!")); //This creates a bare minimum GELF message
writeln(Message("localhost","HUGE ERROR!", Level.ERROR)); //This example uses the overloaded contructor to report an error

GELF messages can also be created in multiple steps. This allows you to add in custom values using loops or other code

// Let's create a GELF message using properties
auto m = Message("localhost","HUGE ERROR!");
m.level = Level.ERROR;
m.timestamp = Clock.currTime();
m.a_number = 7;

// Now let's add some environment variables in
import std.process;
foreach(v, k; environment.toAA())
    m[k] = v;

writeln(m); // {"version":1.1, "host:"localhost", "short_message":"HUGE ERROR!", "timestamp":1447275799, "level":3, "_a_number":7, "_PATH":"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games", ...}

A simpler method is to use a fluent interface. This example also shows how values from a Message can be read and used in a conditional statement.

// Use the fluent interface ..
auto m1 = Message("localhost", "Divide by zero error").level(Level.ERROR).timestamp(Clock.currTime()).numerator(1000).PATH("/usr/bin/");

// Values can be checked for conditions. Here we only send messages of Level.ERROR or more severity to Graylog
if(m1.level <= Level.ERROR) {
    auto s = new UdpSocket();
    s.connect(new InternetAddress("localhost", 11200));
    s.send(m1.toString());
}

writeln(m1); //{"version":1.1, "host:"localhost", "short_message":"Divide by zero error", "timestamp":1447274923, "level":3, "_numerator":1000, "_PATH":"/usr/bin/"}

Meta