Skip to main content

google_cloud_logging_type/
model.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16
17#![allow(rustdoc::redundant_explicit_links)]
18#![allow(rustdoc::broken_intra_doc_links)]
19#![no_implicit_prelude]
20extern crate bytes;
21extern crate serde;
22extern crate serde_json;
23extern crate serde_with;
24extern crate std;
25extern crate wkt;
26
27mod debug;
28mod deserialize;
29mod serialize;
30
31/// A common proto for logging HTTP requests. Only contains semantics
32/// defined by the HTTP specification. Product-specific logging
33/// information MUST be defined in a separate message.
34#[derive(Clone, Default, PartialEq)]
35#[non_exhaustive]
36pub struct HttpRequest {
37    /// The request method. Examples: `"GET"`, `"HEAD"`, `"PUT"`, `"POST"`.
38    pub request_method: std::string::String,
39
40    /// The scheme (http, https), the host name, the path and the query
41    /// portion of the URL that was requested.
42    /// Example: ``http://example.com/some/info?color=red``.
43    pub request_url: std::string::String,
44
45    /// The size of the HTTP request message in bytes, including the request
46    /// headers and the request body.
47    pub request_size: i64,
48
49    /// The response code indicating the status of response.
50    /// Examples: 200, 404.
51    pub status: i32,
52
53    /// The size of the HTTP response message sent back to the client, in bytes,
54    /// including the response headers and the response body.
55    pub response_size: i64,
56
57    /// The user agent sent by the client. Example:
58    /// `"Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET
59    /// CLR 1.0.3705)"`.
60    pub user_agent: std::string::String,
61
62    /// The IP address (IPv4 or IPv6) of the client that issued the HTTP
63    /// request. This field can include port information. Examples:
64    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
65    pub remote_ip: std::string::String,
66
67    /// The IP address (IPv4 or IPv6) of the origin server that the request was
68    /// sent to. This field can include port information. Examples:
69    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
70    pub server_ip: std::string::String,
71
72    /// The referer URL of the request, as defined in
73    /// [HTTP/1.1 Header Field
74    /// Definitions](https://datatracker.ietf.org/doc/html/rfc2616#section-14.36).
75    pub referer: std::string::String,
76
77    /// The request processing latency on the server, from the time the request was
78    /// received until the response was sent.
79    pub latency: std::option::Option<wkt::Duration>,
80
81    /// Whether or not a cache lookup was attempted.
82    pub cache_lookup: bool,
83
84    /// Whether or not an entity was served from cache
85    /// (with or without validation).
86    pub cache_hit: bool,
87
88    /// Whether or not the response was validated with the origin server before
89    /// being served from cache. This field is only meaningful if `cache_hit` is
90    /// True.
91    pub cache_validated_with_origin_server: bool,
92
93    /// The number of HTTP response bytes inserted into cache. Set only when a
94    /// cache fill was attempted.
95    pub cache_fill_bytes: i64,
96
97    /// Protocol used for the request. Examples: "HTTP/1.1", "HTTP/2", "websocket"
98    pub protocol: std::string::String,
99
100    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
101}
102
103impl HttpRequest {
104    /// Creates a new default instance.
105    pub fn new() -> Self {
106        std::default::Default::default()
107    }
108
109    /// Sets the value of [request_method][crate::model::HttpRequest::request_method].
110    ///
111    /// # Example
112    /// ```ignore,no_run
113    /// # use google_cloud_logging_type::model::HttpRequest;
114    /// let x = HttpRequest::new().set_request_method("example");
115    /// ```
116    pub fn set_request_method<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
117        self.request_method = v.into();
118        self
119    }
120
121    /// Sets the value of [request_url][crate::model::HttpRequest::request_url].
122    ///
123    /// # Example
124    /// ```ignore,no_run
125    /// # use google_cloud_logging_type::model::HttpRequest;
126    /// let x = HttpRequest::new().set_request_url("example");
127    /// ```
128    pub fn set_request_url<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
129        self.request_url = v.into();
130        self
131    }
132
133    /// Sets the value of [request_size][crate::model::HttpRequest::request_size].
134    ///
135    /// # Example
136    /// ```ignore,no_run
137    /// # use google_cloud_logging_type::model::HttpRequest;
138    /// let x = HttpRequest::new().set_request_size(42);
139    /// ```
140    pub fn set_request_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
141        self.request_size = v.into();
142        self
143    }
144
145    /// Sets the value of [status][crate::model::HttpRequest::status].
146    ///
147    /// # Example
148    /// ```ignore,no_run
149    /// # use google_cloud_logging_type::model::HttpRequest;
150    /// let x = HttpRequest::new().set_status(42);
151    /// ```
152    pub fn set_status<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
153        self.status = v.into();
154        self
155    }
156
157    /// Sets the value of [response_size][crate::model::HttpRequest::response_size].
158    ///
159    /// # Example
160    /// ```ignore,no_run
161    /// # use google_cloud_logging_type::model::HttpRequest;
162    /// let x = HttpRequest::new().set_response_size(42);
163    /// ```
164    pub fn set_response_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
165        self.response_size = v.into();
166        self
167    }
168
169    /// Sets the value of [user_agent][crate::model::HttpRequest::user_agent].
170    ///
171    /// # Example
172    /// ```ignore,no_run
173    /// # use google_cloud_logging_type::model::HttpRequest;
174    /// let x = HttpRequest::new().set_user_agent("example");
175    /// ```
176    pub fn set_user_agent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
177        self.user_agent = v.into();
178        self
179    }
180
181    /// Sets the value of [remote_ip][crate::model::HttpRequest::remote_ip].
182    ///
183    /// # Example
184    /// ```ignore,no_run
185    /// # use google_cloud_logging_type::model::HttpRequest;
186    /// let x = HttpRequest::new().set_remote_ip("example");
187    /// ```
188    pub fn set_remote_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
189        self.remote_ip = v.into();
190        self
191    }
192
193    /// Sets the value of [server_ip][crate::model::HttpRequest::server_ip].
194    ///
195    /// # Example
196    /// ```ignore,no_run
197    /// # use google_cloud_logging_type::model::HttpRequest;
198    /// let x = HttpRequest::new().set_server_ip("example");
199    /// ```
200    pub fn set_server_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
201        self.server_ip = v.into();
202        self
203    }
204
205    /// Sets the value of [referer][crate::model::HttpRequest::referer].
206    ///
207    /// # Example
208    /// ```ignore,no_run
209    /// # use google_cloud_logging_type::model::HttpRequest;
210    /// let x = HttpRequest::new().set_referer("example");
211    /// ```
212    pub fn set_referer<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
213        self.referer = v.into();
214        self
215    }
216
217    /// Sets the value of [latency][crate::model::HttpRequest::latency].
218    ///
219    /// # Example
220    /// ```ignore,no_run
221    /// # use google_cloud_logging_type::model::HttpRequest;
222    /// use wkt::Duration;
223    /// let x = HttpRequest::new().set_latency(Duration::default()/* use setters */);
224    /// ```
225    pub fn set_latency<T>(mut self, v: T) -> Self
226    where
227        T: std::convert::Into<wkt::Duration>,
228    {
229        self.latency = std::option::Option::Some(v.into());
230        self
231    }
232
233    /// Sets or clears the value of [latency][crate::model::HttpRequest::latency].
234    ///
235    /// # Example
236    /// ```ignore,no_run
237    /// # use google_cloud_logging_type::model::HttpRequest;
238    /// use wkt::Duration;
239    /// let x = HttpRequest::new().set_or_clear_latency(Some(Duration::default()/* use setters */));
240    /// let x = HttpRequest::new().set_or_clear_latency(None::<Duration>);
241    /// ```
242    pub fn set_or_clear_latency<T>(mut self, v: std::option::Option<T>) -> Self
243    where
244        T: std::convert::Into<wkt::Duration>,
245    {
246        self.latency = v.map(|x| x.into());
247        self
248    }
249
250    /// Sets the value of [cache_lookup][crate::model::HttpRequest::cache_lookup].
251    ///
252    /// # Example
253    /// ```ignore,no_run
254    /// # use google_cloud_logging_type::model::HttpRequest;
255    /// let x = HttpRequest::new().set_cache_lookup(true);
256    /// ```
257    pub fn set_cache_lookup<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
258        self.cache_lookup = v.into();
259        self
260    }
261
262    /// Sets the value of [cache_hit][crate::model::HttpRequest::cache_hit].
263    ///
264    /// # Example
265    /// ```ignore,no_run
266    /// # use google_cloud_logging_type::model::HttpRequest;
267    /// let x = HttpRequest::new().set_cache_hit(true);
268    /// ```
269    pub fn set_cache_hit<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
270        self.cache_hit = v.into();
271        self
272    }
273
274    /// Sets the value of [cache_validated_with_origin_server][crate::model::HttpRequest::cache_validated_with_origin_server].
275    ///
276    /// # Example
277    /// ```ignore,no_run
278    /// # use google_cloud_logging_type::model::HttpRequest;
279    /// let x = HttpRequest::new().set_cache_validated_with_origin_server(true);
280    /// ```
281    pub fn set_cache_validated_with_origin_server<T: std::convert::Into<bool>>(
282        mut self,
283        v: T,
284    ) -> Self {
285        self.cache_validated_with_origin_server = v.into();
286        self
287    }
288
289    /// Sets the value of [cache_fill_bytes][crate::model::HttpRequest::cache_fill_bytes].
290    ///
291    /// # Example
292    /// ```ignore,no_run
293    /// # use google_cloud_logging_type::model::HttpRequest;
294    /// let x = HttpRequest::new().set_cache_fill_bytes(42);
295    /// ```
296    pub fn set_cache_fill_bytes<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
297        self.cache_fill_bytes = v.into();
298        self
299    }
300
301    /// Sets the value of [protocol][crate::model::HttpRequest::protocol].
302    ///
303    /// # Example
304    /// ```ignore,no_run
305    /// # use google_cloud_logging_type::model::HttpRequest;
306    /// let x = HttpRequest::new().set_protocol("example");
307    /// ```
308    pub fn set_protocol<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
309        self.protocol = v.into();
310        self
311    }
312}
313
314impl wkt::message::Message for HttpRequest {
315    fn typename() -> &'static str {
316        "type.googleapis.com/google.logging.type.HttpRequest"
317    }
318}
319
320/// The severity of the event described in a log entry, expressed as one of the
321/// standard severity levels listed below.  For your reference, the levels are
322/// assigned the listed numeric values. The effect of using numeric values other
323/// than those listed is undefined.
324///
325/// You can filter for log entries by severity.  For example, the following
326/// filter expression will match log entries with severities `INFO`, `NOTICE`,
327/// and `WARNING`:
328///
329/// ```norust
330/// severity > DEBUG AND severity <= WARNING
331/// ```
332///
333/// If you are writing log entries, you should map other severity encodings to
334/// one of these standard levels. For example, you might map all of Java's FINE,
335/// FINER, and FINEST levels to `LogSeverity.DEBUG`. You can preserve the
336/// original severity level in the log entry payload if you wish.
337///
338/// # Working with unknown values
339///
340/// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
341/// additional enum variants at any time. Adding new variants is not considered
342/// a breaking change. Applications should write their code in anticipation of:
343///
344/// - New values appearing in future releases of the client library, **and**
345/// - New values received dynamically, without application changes.
346///
347/// Please consult the [Working with enums] section in the user guide for some
348/// guidelines.
349///
350/// [Working with enums]: https://googleapis.github.io/google-cloud-rust/working_with_enums.html
351#[derive(Clone, Debug, PartialEq)]
352#[non_exhaustive]
353pub enum LogSeverity {
354    /// (0) The log entry has no assigned severity level.
355    Default,
356    /// (100) Debug or trace information.
357    Debug,
358    /// (200) Routine information, such as ongoing status or performance.
359    Info,
360    /// (300) Normal but significant events, such as start up, shut down, or
361    /// a configuration change.
362    Notice,
363    /// (400) Warning events might cause problems.
364    Warning,
365    /// (500) Error events are likely to cause problems.
366    Error,
367    /// (600) Critical events cause more severe problems or outages.
368    Critical,
369    /// (700) A person must take an action immediately.
370    Alert,
371    /// (800) One or more systems are unusable.
372    Emergency,
373    /// If set, the enum was initialized with an unknown value.
374    ///
375    /// Applications can examine the value using [LogSeverity::value] or
376    /// [LogSeverity::name].
377    UnknownValue(log_severity::UnknownValue),
378}
379
380#[doc(hidden)]
381pub mod log_severity {
382    #[allow(unused_imports)]
383    use super::*;
384    #[derive(Clone, Debug, PartialEq)]
385    pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
386}
387
388impl LogSeverity {
389    /// Gets the enum value.
390    ///
391    /// Returns `None` if the enum contains an unknown value deserialized from
392    /// the string representation of enums.
393    pub fn value(&self) -> std::option::Option<i32> {
394        match self {
395            Self::Default => std::option::Option::Some(0),
396            Self::Debug => std::option::Option::Some(100),
397            Self::Info => std::option::Option::Some(200),
398            Self::Notice => std::option::Option::Some(300),
399            Self::Warning => std::option::Option::Some(400),
400            Self::Error => std::option::Option::Some(500),
401            Self::Critical => std::option::Option::Some(600),
402            Self::Alert => std::option::Option::Some(700),
403            Self::Emergency => std::option::Option::Some(800),
404            Self::UnknownValue(u) => u.0.value(),
405        }
406    }
407
408    /// Gets the enum value as a string.
409    ///
410    /// Returns `None` if the enum contains an unknown value deserialized from
411    /// the integer representation of enums.
412    pub fn name(&self) -> std::option::Option<&str> {
413        match self {
414            Self::Default => std::option::Option::Some("DEFAULT"),
415            Self::Debug => std::option::Option::Some("DEBUG"),
416            Self::Info => std::option::Option::Some("INFO"),
417            Self::Notice => std::option::Option::Some("NOTICE"),
418            Self::Warning => std::option::Option::Some("WARNING"),
419            Self::Error => std::option::Option::Some("ERROR"),
420            Self::Critical => std::option::Option::Some("CRITICAL"),
421            Self::Alert => std::option::Option::Some("ALERT"),
422            Self::Emergency => std::option::Option::Some("EMERGENCY"),
423            Self::UnknownValue(u) => u.0.name(),
424        }
425    }
426}
427
428impl std::default::Default for LogSeverity {
429    fn default() -> Self {
430        use std::convert::From;
431        Self::from(0)
432    }
433}
434
435impl std::fmt::Display for LogSeverity {
436    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
437        wkt::internal::display_enum(f, self.name(), self.value())
438    }
439}
440
441impl std::convert::From<i32> for LogSeverity {
442    fn from(value: i32) -> Self {
443        match value {
444            0 => Self::Default,
445            100 => Self::Debug,
446            200 => Self::Info,
447            300 => Self::Notice,
448            400 => Self::Warning,
449            500 => Self::Error,
450            600 => Self::Critical,
451            700 => Self::Alert,
452            800 => Self::Emergency,
453            _ => Self::UnknownValue(log_severity::UnknownValue(
454                wkt::internal::UnknownEnumValue::Integer(value),
455            )),
456        }
457    }
458}
459
460impl std::convert::From<&str> for LogSeverity {
461    fn from(value: &str) -> Self {
462        use std::string::ToString;
463        match value {
464            "DEFAULT" => Self::Default,
465            "DEBUG" => Self::Debug,
466            "INFO" => Self::Info,
467            "NOTICE" => Self::Notice,
468            "WARNING" => Self::Warning,
469            "ERROR" => Self::Error,
470            "CRITICAL" => Self::Critical,
471            "ALERT" => Self::Alert,
472            "EMERGENCY" => Self::Emergency,
473            _ => Self::UnknownValue(log_severity::UnknownValue(
474                wkt::internal::UnknownEnumValue::String(value.to_string()),
475            )),
476        }
477    }
478}
479
480impl serde::ser::Serialize for LogSeverity {
481    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
482    where
483        S: serde::Serializer,
484    {
485        match self {
486            Self::Default => serializer.serialize_i32(0),
487            Self::Debug => serializer.serialize_i32(100),
488            Self::Info => serializer.serialize_i32(200),
489            Self::Notice => serializer.serialize_i32(300),
490            Self::Warning => serializer.serialize_i32(400),
491            Self::Error => serializer.serialize_i32(500),
492            Self::Critical => serializer.serialize_i32(600),
493            Self::Alert => serializer.serialize_i32(700),
494            Self::Emergency => serializer.serialize_i32(800),
495            Self::UnknownValue(u) => u.0.serialize(serializer),
496        }
497    }
498}
499
500impl<'de> serde::de::Deserialize<'de> for LogSeverity {
501    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
502    where
503        D: serde::Deserializer<'de>,
504    {
505        deserializer.deserialize_any(wkt::internal::EnumVisitor::<LogSeverity>::new(
506            ".google.logging.type.LogSeverity",
507        ))
508    }
509}