gelfcpp::GelfMessage Class Reference

A single GELF message, with write-only access to its fields. More...

#include <GelfMessage.hpp>

Public Member Functions

void SetMessage (const std::string &message)
 Quick accessor for short_message field. More...
 
void SetFullMessage (const std::string &message)
 Quick accessor for full_message field. More...
 
void SetHost (const std::string &host)
 Quick accessor for host field. More...
 
void SetTimestamp (double timestamp)
 Quick accessor for timestamp field. More...
 
template<typename T >
void SetField (const std::string &name, T value)
 Adds a field to the message. More...
 
FieldSetter operator[] (const std::string &field)
 Adds a field to the message. More...
 

Detailed Description

A single GELF message, with write-only access to its fields.

Note
This class only supports GELF version 1.1 and treats deprecated standard fields as normal additional fields.

Currently the following standard fields are handled: version, host, short_message, full_message, timestamp, level. Standard fields are included "as-is". All other fields are prefixed with "_".

Member Function Documentation

FieldSetter gelfcpp::GelfMessage::operator[] ( const std::string &  field)
inline

Adds a field to the message.

This behaves like SetField(const std::string&, T) but allows map/array like syntax.

Example usage:

GelfMessage message;
message["field_name"] = field_value;
Parameters
fieldfield name, the "_" prefix is added automatically
Returns
wrapper to allow assignment, see the usage example.
template<typename T >
void gelfcpp::GelfMessage::SetField ( const std::string &  name,
value 
)
inline

Adds a field to the message.

Note
If a field was already assigned the old value is overwritten.
Template Parameters
Tvalue type, supported: bool, integral, floating point, strings
Parameters
namefield name, the "_" prefix is added automatically
valuefield value of any supported type
void gelfcpp::GelfMessage::SetFullMessage ( const std::string &  message)
inline

Quick accessor for full_message field.

Behaves like

SetField("full_message", message).
Parameters
messagemessage
void gelfcpp::GelfMessage::SetHost ( const std::string &  host)
inline

Quick accessor for host field.

Behaves like

SetField("host", message).
Parameters
hosthostname
void gelfcpp::GelfMessage::SetMessage ( const std::string &  message)
inline

Quick accessor for short_message field.

Behaves like

SetField("short_message", message).
Parameters
messagemessage
void gelfcpp::GelfMessage::SetTimestamp ( double  timestamp)
inline

Quick accessor for timestamp field.

Behaves like

SetField("timestamp", message).
Parameters
timestamptimestamp

The documentation for this class was generated from the following file: