[][src]Trait serde_gelf::GelfRecordBuilder

pub trait GelfRecordBuilder {
    fn new() -> Self;
fn set_message(self, short_message: String) -> Self;
fn set_level(self, level: GelfLevel) -> Self;
fn set_timestamp(self, timestamp: f64) -> Self;
fn add_additional_fields(
        self,
        additional_fields: BTreeMap<Value, Value>
    ) -> Self;
fn extend_additional_fields(
        self,
        additional_fields: BTreeMap<Value, Value>
    ) -> Self;
fn set_facility(self, facility: String) -> Self;
fn set_line(self, line: u32) -> Self;
fn set_file(self, file: String) -> Self;
fn set_full_message(self, full_message: Option<String>) -> Self; }

Builder for GelfRecord.

Examples

use serde_gelf::{GelfRecord, GelfLevel};

let rec = GelfRecord::new()
    .set_file("main.rs".into())
    .set_facility("main".into())
    .set_level(GelfLevel::Notice)
    .set_line(50)
    .set_message("Hello".into());

Required methods

fn new() -> Self

Construct new GelfRecordBuilder.

fn set_message(self, short_message: String) -> Self

Set GelfRecord.short_message.

fn set_level(self, level: GelfLevel) -> Self

Set GelfRecord.level.

fn set_timestamp(self, timestamp: f64) -> Self

Set GelfRecord.timestamp.

Example


use serde_gelf::GelfRecord;
use std::time::{SystemTime, UNIX_EPOCH};

let rec = GelfRecord::new()
    .set_timestamp({
        let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
         now.as_secs() as f64 + f64::from(now.subsec_nanos()) / 1e9
});

fn add_additional_fields(
    self,
    additional_fields: BTreeMap<Value, Value>
) -> Self

Extend a non-flatten dict to GelfRecord.additional_fields.

Example

use std::collections::BTreeMap;
use serde_gelf::{GelfRecord, GelfLevel};

let mut extra = BTreeMap::new();
extra.insert("integer".into(),  serde_value::Value::I8(10));

let rec = GelfRecord::new()
    .extend_additional_fields(extra);

fn extend_additional_fields(
    self,
    additional_fields: BTreeMap<Value, Value>
) -> Self

Extend a already flatten dict to GelfRecord.additional_fields.

Example

use std::collections::BTreeMap;
use serde_gelf::{GelfRecord, GelfLevel, to_flat_dict};

let mut extra = BTreeMap::new();
extra.insert("integer".into(),  serde_value::Value::I8(10));

let rec = GelfRecord::new()
    .extend_additional_fields(to_flat_dict(&extra).unwrap());

fn set_facility(self, facility: String) -> Self

Set GelfRecord.facility.

fn set_line(self, line: u32) -> Self

Set GelfRecord.line.

fn set_file(self, file: String) -> Self

Set GelfRecord.file.

fn set_full_message(self, full_message: Option<String>) -> Self

Set GelfRecord.full_message.

Loading content...

Implementors

impl GelfRecordBuilder for GelfRecord[src]

fn new() -> GelfRecord[src]

Construct new GelfRecord.

fn set_message(self, short_message: String) -> Self[src]

Set GelfRecord.short_message.

fn set_level(self, level: GelfLevel) -> Self[src]

Set GelfRecord.level.

fn set_timestamp(self, timestamp: f64) -> Self[src]

Set GelfRecord.timestamp.

Example


use serde_gelf::GelfRecord;
use std::time::{SystemTime, UNIX_EPOCH};

let rec = GelfRecord::new()
    .set_timestamp({
        let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
         now.as_secs() as f64 + f64::from(now.subsec_nanos()) / 1e9
});

fn add_additional_fields(
    self,
    additional_fields: BTreeMap<Value, Value>
) -> Self
[src]

Extend a already flatten dict to GelfRecord.additional_fields.

Example

use std::collections::BTreeMap;
use serde_gelf::{GelfRecord, GelfLevel, to_flat_dict};

let mut extra = BTreeMap::new();
extra.insert("integer".into(),  serde_value::Value::I8(10));

let rec = GelfRecord::new()
    .extend_additional_fields(to_flat_dict(&extra).unwrap());

fn extend_additional_fields(
    self,
    additional_fields: BTreeMap<Value, Value>
) -> Self
[src]

Extend a already flatten dict to GelfRecord.additional_fields.

Example

use std::collections::BTreeMap;
use serde_gelf::{GelfRecord, GelfLevel, to_flat_dict};

let mut extra = BTreeMap::new();
extra.insert("integer".into(),  serde_value::Value::I8(10));

let rec = GelfRecord::new()
    .extend_additional_fields(to_flat_dict(&extra).unwrap());

fn set_facility(self, facility: String) -> Self[src]

Set GelfRecord.facility.

fn set_line(self, line: u32) -> Self[src]

Set GelfRecord.line.

fn set_file(self, file: String) -> Self[src]

Set GelfRecord.file.

fn set_full_message(self, full_message: Option<String>) -> Self[src]

Set GelfRecord.full_message.

Loading content...