1//! # OpenTelemetry Logs Bridge API
2/// This API is not intended to be called by application developers directly.
3/// It is provided for logging library authors to build log appenders, that
4/// bridges existing logging systems with OpenTelemetry.
5use crate::ExportError;
67use std::{sync::PoisonError, time::Duration};
8use thiserror::Error;
910mod logger;
11mod noop;
12mod record;
1314pub use logger::{Logger, LoggerProvider};
15pub use noop::NoopLoggerProvider;
16pub use record::{AnyValue, LogRecord, Severity};
1718/// Describe the result of operations in log SDK.
19pub type LogResult<T> = Result<T, LogError>;
2021#[derive(Error, Debug)]
22#[non_exhaustive]
23/// Errors returned by the log SDK.
24pub enum LogError {
25/// Export failed with the error returned by the exporter.
26#[error("Exporter {} encountered the following errors: {0}", .0.exporter_name())]
27ExportFailed(Box<dyn ExportError>),
2829/// Export failed to finish after certain period and processor stopped the export.
30#[error("Exporter timed out after {} seconds", .0.as_secs())]
31ExportTimedOut(Duration),
3233/// Other errors propagated from log SDK that weren't covered above.
34#[error(transparent)]
35Other(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
36}
3738impl<T> From<T> for LogError
39where
40T: ExportError,
41{
42fn from(err: T) -> Self {
43 LogError::ExportFailed(Box::new(err))
44 }
45}
4647impl From<String> for LogError {
48fn from(err_msg: String) -> Self {
49 LogError::Other(Box::new(Custom(err_msg)))
50 }
51}
5253impl From<&'static str> for LogError {
54fn from(err_msg: &'static str) -> Self {
55 LogError::Other(Box::new(Custom(err_msg.into())))
56 }
57}
5859impl<T> From<PoisonError<T>> for LogError {
60fn from(err: PoisonError<T>) -> Self {
61 LogError::Other(err.to_string().into())
62 }
63}
64/// Wrap type for string
65#[derive(Error, Debug)]
66#[error("{0}")]
67struct Custom(String);