pub struct GelfMessage { /* private fields */ }Expand description
One GELF 1.1 message. Build it with GelfMessage::new and
set_field, or from a LogRecord with
GelfMessage::from_log_record. Display renders the compact JSON text.
Implementations§
Source§impl GelfMessage
impl GelfMessage
Sourcepub fn new(opts: GelfMessageOptions) -> Result<GelfMessage>
pub fn new(opts: GelfMessageOptions) -> Result<GelfMessage>
Validates opts and returns a message (VALIDATION for a blank host or short message or
a bad field key).
Sourcepub fn simple(
host: impl Into<String>,
short_message: impl Into<String>,
) -> Result<Self>
pub fn simple( host: impl Into<String>, short_message: impl Into<String>, ) -> Result<Self>
Shorthand for a message with only host and short_message.
Sourcepub fn set_field(
&mut self,
key: &str,
value: impl Into<AttrValue>,
) -> Result<()>
pub fn set_field( &mut self, key: &str, value: impl Into<AttrValue>, ) -> Result<()>
Sets an additional field (name or _name). The key is validated with
validate_gelf_field_key, the value mapped with gelf_field_value; null removes
the field.
Sourcepub fn with_field(self, key: &str, value: impl Into<AttrValue>) -> Result<Self>
pub fn with_field(self, key: &str, value: impl Into<AttrValue>) -> Result<Self>
Builder form of set_field.
Sourcepub fn short_message(&self) -> &str
pub fn short_message(&self) -> &str
short_message.
Sourcepub fn full_message(&self) -> Option<&str>
pub fn full_message(&self) -> Option<&str>
full_message, when set.
Sourcepub fn timestamp(&self) -> Option<SystemTime>
pub fn timestamp(&self) -> Option<SystemTime>
Event time, when set.
Sourcepub fn to_value(&self) -> Value
pub fn to_value(&self) -> Value
The GELF wire object: version, host, short_message and, when set,
full_message, timestamp, level and the additional fields (keys sorted).
Sourcepub fn from_log_record(
record: &LogRecord,
opts: &FromLogRecordOptions,
) -> GelfMessage
pub fn from_log_record( record: &LogRecord, opts: &FromLogRecordOptions, ) -> GelfMessage
Converts a record with the mapping shared by all five languages: host =
resource["host.name"] (else opts.host, else the local host name); short_message =
body (- when blank); timestamp; level from the severity; resource attributes
flattened with dotted keys (except host.name), then the record attributes (they win),
then _trace_id, _span_id and _trace_flags (numeric). Keys go through
gelf_field_key, values through gelf_field_value.