Skip to main content

grow_graylog/
lib.rs

1// Skeleton created by sdk-kit 0.1.0; owned by this repository (edit freely).
2//! # grow-graylog
3//!
4//! Rust SDK for [Graylog Open](https://grow-codes-packages.github.io/graylog/) by Grow Codes.
5//!
6//! ```no_run
7//! # async fn demo() -> grow_graylog::Result<()> {
8//! use grow_graylog::logging::{attrs, LogClient, LogQueryClient, WaitOptions};
9//! use grow_graylog::{GraylogClient, GraylogConfig, LogOptions, LogQueryOptions};
10//!
11//! let client = GraylogClient::new(GraylogConfig::from_env()?)?;
12//! let health = client.health().await?;
13//! println!("healthy: {}", health.healthy);
14//!
15//! // GELF over the configured protocol (TCP by default), batched.
16//! let logs = client.new_log_client(LogOptions::default().resource_attribute("service.name", "checkout"))?;
17//! logs.logger(Some("http"), attrs! {}).info("order placed", attrs! { "order_id" => "o-1" });
18//! logs.flush(None).await?;
19//!
20//! // Read it back through the Views search API.
21//! let record = client
22//!     .log_query(LogQueryOptions::default())
23//!     .wait_for_log("order_id:o-1", WaitOptions::default())
24//!     .await?;
25//! println!("{}", record.body);
26//! client.close().await;
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! Modules: GELF messages and transports ([`GelfMessage`], [`GelfUdpTransport`],
32//! [`GelfTcpTransport`], [`GelfHttpTransport`]), the optional OTLP/gRPC exporter
33//! ([`OtlpGrpcLogExporter`]), search ([`GraylogClient::search`],
34//! [`GraylogClient::search_relative`], [`GraylogClient::get_message`]), admin (inputs, streams,
35//! index sets, [`GraylogClient::system_info`]) and the logging category
36//! ([`GraylogClient::new_log_client`], [`GraylogClient::log_query`]).
37//!
38//! Features: `blocking` (a blocking client), `testing` (in-memory fakes and the conformance
39//! runner), `tracing-layer` and `log-bridge` (logging adapters, on by default).
40//!
41//! Graylog is a trademark of Graylog, Inc. This project is not affiliated with or endorsed by
42//! Graylog, Inc.
43#![cfg_attr(docsrs, feature(doc_cfg))]
44
45pub mod core;
46
47mod admin;
48mod client;
49mod config;
50mod exporter;
51mod gelf;
52mod gelf_transport;
53mod logquery;
54mod models;
55mod otlp;
56mod search;
57mod tls;
58
59#[cfg(feature = "blocking")]
60#[cfg_attr(docsrs, doc(cfg(feature = "blocking")))]
61pub mod blocking;
62
63#[cfg(feature = "testing")]
64#[cfg_attr(docsrs, doc(cfg(feature = "testing")))]
65pub mod testing;
66
67pub mod logging;
68
69pub use crate::core::{Error, ErrorCode, HealthStatus, Result, RetryPolicy, Secret};
70
71pub use crate::config::{
72    GelfProtocol, DEFAULT_GELF_HTTP_PORT, DEFAULT_GELF_PORT, DEFAULT_OTLP_GRPC_PORT,
73    DEFAULT_REQUESTED_BY, DEFAULT_URL,
74};
75
76pub use crate::client::{GraylogClient, HEADER_NODE_ID, HEADER_REQUESTED_BY};
77
78pub use crate::admin::{
79    CreateInputOptions, CreateStreamOptions, EnsureGelfInputOptions, EnsuredInput,
80    ListStreamsOptions,
81};
82pub use crate::exporter::{GelfLogExporter, GelfTransportOptions, LogOptions};
83pub use crate::gelf::{
84    flatten_attributes, gelf_field_key, gelf_field_value, gelf_level_to_severity, gelf_timestamp,
85    severity_to_gelf_level, validate_gelf_field_key, FromLogRecordOptions, GelfLevel, GelfMessage,
86    GelfMessageOptions, GELF_VERSION,
87};
88pub use crate::gelf_transport::{
89    encode_gelf_udp, frame_gelf_tcp, GelfCompression, GelfHttpOptions, GelfHttpTransport,
90    GelfSendOptions, GelfSendResult, GelfTcpOptions, GelfTcpTransport, GelfTransport,
91    GelfUdpOptions, GelfUdpTransport, DEFAULT_UDP_CHUNK_SIZE, GELF_CHUNK_HEADER_SIZE,
92    GELF_CHUNK_MAGIC, GELF_MAX_CHUNKS,
93};
94pub use crate::logquery::{
95    LogQuery, LogQueryOptions, DEFAULT_LOG_QUERY_WINDOW, DEFAULT_TAIL_INTERVAL,
96};
97pub use crate::models::{
98    IndexSet, Input, InputState, Stream, StreamPage, StreamRule, SystemInfo, INPUT_STATE_FAILED,
99    INPUT_STATE_RUNNING, INPUT_TYPE_GELF_HTTP, INPUT_TYPE_GELF_TCP, INPUT_TYPE_GELF_UDP,
100    INPUT_TYPE_OTEL_GRPC, STREAM_RULE_ALWAYS_MATCH, STREAM_RULE_CONTAINS, STREAM_RULE_EXACT,
101    STREAM_RULE_GREATER, STREAM_RULE_MATCH_INPUT, STREAM_RULE_PRESENCE, STREAM_RULE_REGEX,
102    STREAM_RULE_SMALLER,
103};
104pub use crate::otlp::{
105    decode_export_logs_response, encode_export_logs_request, error_for_grpc_status,
106    OtlpGrpcLogExporter, OtlpGrpcLogExporterOptions, OtlpPartialSuccess, OTLP_LOGS_EXPORT_PATH,
107    OTLP_SCOPE_NAME,
108};
109pub use crate::search::{
110    log_record_from_message, Message, MessageSearchOptions, MessageSearchResult, SearchSort,
111    DEFAULT_MESSAGE_SORT_FIELD, DEFAULT_SEARCH_LIMIT, DEFAULT_SEARCH_RANGE, MAX_SEARCH_LIMIT,
112    RESOURCE_FIELDS,
113};
114
115pub use crate::config::GraylogConfig;
116
117pub use crate::config::GraylogConfigBuilder;
118
119/// Service-prefixed alias of [`Error`].
120pub type GraylogError = Error;