LogScaleStructuredLogger

Struct LogScaleStructuredLogger 

Source
pub struct LogScaleStructuredLogger { /* private fields */ }

Implementations§

Source§

impl LogScaleStructuredLogger

Source

pub fn init( url: String, ingest_token: String, options: LoggerOptions, ) -> Result<(), Box<dyn Error>>

Examples found in repository?
examples/log_structured.rs (lines 21-25)
13async fn main() {
14    let args: Vec<String> = env::args().collect();
15
16    let ingest_token = args
17        .get(1)
18        .expect("Missing '--ingest-token' parameter.")
19        .replace("--ingest-token=", "");
20
21    LogScaleStructuredLogger::init(
22        String::from("https://cloud.community.humio.com"),
23        ingest_token,
24        LoggerOptions::default()
25    )
26    .unwrap();
27
28    log::set_max_level(log::LevelFilter::Trace);
29
30    let nested = Nested {x: 42, y: String::from("some string parameter.")};
31    let mut count = 0;
32    
33    // Loop to let the background sync task have time to do its thing.
34    loop {
35        info!("Plain log only with text, no variables");
36
37        error!("You can of course also use any other log level, like error.");
38
39        info!(count = format!("{}", count); "You can also add structured values to your logs, which will automatically be included as attributes in your LogScale logs.");
40
41        info!(target: "api",
42            method = "GET", 
43            path = "/hello", 
44            status = 200_u16, 
45            elapsed = 10_u64, 
46            nested = log::as_serde!(nested); 
47            "You can also create logs with multiple structured values, and even nested JSON values.",);
48
49        std::thread::sleep(Duration::from_secs(1));
50        
51        count += 1;
52    }
53}

Trait Implementations§

Source§

impl Writer for LogScaleStructuredLogger

Source§

fn write_log(&self, value: &BTreeMap<Key<'_>, Value<'_>>) -> Result<(), Error>

Writes a structured log to the underlying io::Write instance.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,