pub struct Builder { /* private fields */ }Expand description
Builder for the Logger
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new(log_name: &str, resource_type: &str) -> Self
pub fn new(log_name: &str, resource_type: &str) -> Self
Creates a Builder object.
§Parameters
log_name: ThelogNamestring to be used in the LogEntryresource_type: The requiredtypefield set in theresourceMonitoredResource object of the LogEntry. For example:k8s_container.
§Example
use slog_google::logger::Builder;
let (drain, _) = Builder::new(
"projects/my-gcp-project/logs/my-log-id",
"k8s_container",
)
.build();Sourcepub fn with_resource_labels(self, labels: Value) -> Result<Self, Box<dyn Error>>
pub fn with_resource_labels(self, labels: Value) -> Result<Self, Box<dyn Error>>
Sets resource labels to be applied.
These labels will populate the labels field in the resource MonitoredResource object of the LogEntry.
§Example
use serde_json::json;
let resource_labels = json!(
{
"pod_name": "dummy-value",
"location": "europe-west1-b",
"pod_name": std::env::var("HOSTNAME").unwrap_or_default(),
"container_name": "my-app",
"project_id": "my-gcp-project",
"cluster_name": "my-gke-cluster",
"namespace_name": "my-gke-namespace"
});
use slog_google::logger::Builder;
let (drain, _) = Builder::new(
"projects/my-gcp-project/logs/my-log-id",
"k8s_container",
)
.with_resource_labels(resource_labels)
.unwrap()
.build();§Errors
Will return Err if labels does not parse as JSON.
Sourcepub fn with_default_labels(self, labels: Value) -> Result<Self, Error>
pub fn with_default_labels(self, labels: Value) -> Result<Self, Error>
Sets default labels to be applied in the labels field.
These will populate the labels top level field of the LogEntry. These labels are added in addition to any labels set in the logger statement.
§Example
use serde_json::json;
let default_labels = json!(
{
"application": "my-application",
"team": "my-team",
"version": "my-app-version",
"role": "my-app-role",
"environment": "production",
"platform": "gcp",
});§Errors
Will return Err if labels does not parse as JSON.
Sourcepub fn with_log_level_label(self, log_level_label: &str) -> Self
pub fn with_log_level_label(self, log_level_label: &str) -> Self
Sourcepub fn build(self) -> (Logger, Receiver<WriteLogEntriesRequest>)
pub fn build(self) -> (Logger, Receiver<WriteLogEntriesRequest>)
This returns a tuple with a Logger, which can be passed to the slog root logger as usual, and a std::sync::mpsc::Receiver channel.
The Logger sends the WriteLogEntries it creates to this channel.
For instance you could output these to the console, if you have an external agent that reads the process’ output and ships it to Google Logging.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more