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
27/// A common proto for logging HTTP requests. Only contains semantics
28/// defined by the HTTP specification. Product-specific logging
29/// information MUST be defined in a separate message.
30#[derive(Clone, Debug, Default, PartialEq)]
31#[non_exhaustive]
32pub struct HttpRequest {
33    /// The request method. Examples: `"GET"`, `"HEAD"`, `"PUT"`, `"POST"`.
34    pub request_method: std::string::String,
35
36    /// The scheme (http, https), the host name, the path and the query
37    /// portion of the URL that was requested.
38    /// Example: ``http://example.com/some/info?color=red``.
39    pub request_url: std::string::String,
40
41    /// The size of the HTTP request message in bytes, including the request
42    /// headers and the request body.
43    pub request_size: i64,
44
45    /// The response code indicating the status of response.
46    /// Examples: 200, 404.
47    pub status: i32,
48
49    /// The size of the HTTP response message sent back to the client, in bytes,
50    /// including the response headers and the response body.
51    pub response_size: i64,
52
53    /// The user agent sent by the client. Example:
54    /// `"Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET
55    /// CLR 1.0.3705)"`.
56    pub user_agent: std::string::String,
57
58    /// The IP address (IPv4 or IPv6) of the client that issued the HTTP
59    /// request. This field can include port information. Examples:
60    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
61    pub remote_ip: std::string::String,
62
63    /// The IP address (IPv4 or IPv6) of the origin server that the request was
64    /// sent to. This field can include port information. Examples:
65    /// `"192.168.1.1"`, `"10.0.0.1:80"`, `"FE80::0202:B3FF:FE1E:8329"`.
66    pub server_ip: std::string::String,
67
68    /// The referer URL of the request, as defined in
69    /// [HTTP/1.1 Header Field
70    /// Definitions](https://datatracker.ietf.org/doc/html/rfc2616#section-14.36).
71    pub referer: std::string::String,
72
73    /// The request processing latency on the server, from the time the request was
74    /// received until the response was sent.
75    pub latency: std::option::Option<wkt::Duration>,
76
77    /// Whether or not a cache lookup was attempted.
78    pub cache_lookup: bool,
79
80    /// Whether or not an entity was served from cache
81    /// (with or without validation).
82    pub cache_hit: bool,
83
84    /// Whether or not the response was validated with the origin server before
85    /// being served from cache. This field is only meaningful if `cache_hit` is
86    /// True.
87    pub cache_validated_with_origin_server: bool,
88
89    /// The number of HTTP response bytes inserted into cache. Set only when a
90    /// cache fill was attempted.
91    pub cache_fill_bytes: i64,
92
93    /// Protocol used for the request. Examples: "HTTP/1.1", "HTTP/2", "websocket"
94    pub protocol: std::string::String,
95
96    _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
97}
98
99impl HttpRequest {
100    pub fn new() -> Self {
101        std::default::Default::default()
102    }
103
104    /// Sets the value of [request_method][crate::model::HttpRequest::request_method].
105    pub fn set_request_method<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
106        self.request_method = v.into();
107        self
108    }
109
110    /// Sets the value of [request_url][crate::model::HttpRequest::request_url].
111    pub fn set_request_url<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
112        self.request_url = v.into();
113        self
114    }
115
116    /// Sets the value of [request_size][crate::model::HttpRequest::request_size].
117    pub fn set_request_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
118        self.request_size = v.into();
119        self
120    }
121
122    /// Sets the value of [status][crate::model::HttpRequest::status].
123    pub fn set_status<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
124        self.status = v.into();
125        self
126    }
127
128    /// Sets the value of [response_size][crate::model::HttpRequest::response_size].
129    pub fn set_response_size<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
130        self.response_size = v.into();
131        self
132    }
133
134    /// Sets the value of [user_agent][crate::model::HttpRequest::user_agent].
135    pub fn set_user_agent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
136        self.user_agent = v.into();
137        self
138    }
139
140    /// Sets the value of [remote_ip][crate::model::HttpRequest::remote_ip].
141    pub fn set_remote_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
142        self.remote_ip = v.into();
143        self
144    }
145
146    /// Sets the value of [server_ip][crate::model::HttpRequest::server_ip].
147    pub fn set_server_ip<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
148        self.server_ip = v.into();
149        self
150    }
151
152    /// Sets the value of [referer][crate::model::HttpRequest::referer].
153    pub fn set_referer<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
154        self.referer = v.into();
155        self
156    }
157
158    /// Sets the value of [latency][crate::model::HttpRequest::latency].
159    pub fn set_latency<T>(mut self, v: T) -> Self
160    where
161        T: std::convert::Into<wkt::Duration>,
162    {
163        self.latency = std::option::Option::Some(v.into());
164        self
165    }
166
167    /// Sets or clears the value of [latency][crate::model::HttpRequest::latency].
168    pub fn set_or_clear_latency<T>(mut self, v: std::option::Option<T>) -> Self
169    where
170        T: std::convert::Into<wkt::Duration>,
171    {
172        self.latency = v.map(|x| x.into());
173        self
174    }
175
176    /// Sets the value of [cache_lookup][crate::model::HttpRequest::cache_lookup].
177    pub fn set_cache_lookup<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
178        self.cache_lookup = v.into();
179        self
180    }
181
182    /// Sets the value of [cache_hit][crate::model::HttpRequest::cache_hit].
183    pub fn set_cache_hit<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
184        self.cache_hit = v.into();
185        self
186    }
187
188    /// Sets the value of [cache_validated_with_origin_server][crate::model::HttpRequest::cache_validated_with_origin_server].
189    pub fn set_cache_validated_with_origin_server<T: std::convert::Into<bool>>(
190        mut self,
191        v: T,
192    ) -> Self {
193        self.cache_validated_with_origin_server = v.into();
194        self
195    }
196
197    /// Sets the value of [cache_fill_bytes][crate::model::HttpRequest::cache_fill_bytes].
198    pub fn set_cache_fill_bytes<T: std::convert::Into<i64>>(mut self, v: T) -> Self {
199        self.cache_fill_bytes = v.into();
200        self
201    }
202
203    /// Sets the value of [protocol][crate::model::HttpRequest::protocol].
204    pub fn set_protocol<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
205        self.protocol = v.into();
206        self
207    }
208}
209
210impl wkt::message::Message for HttpRequest {
211    fn typename() -> &'static str {
212        "type.googleapis.com/google.logging.type.HttpRequest"
213    }
214}
215
216#[doc(hidden)]
217impl<'de> serde::de::Deserialize<'de> for HttpRequest {
218    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
219    where
220        D: serde::Deserializer<'de>,
221    {
222        #[allow(non_camel_case_types)]
223        #[doc(hidden)]
224        #[derive(PartialEq, Eq, Hash)]
225        enum __FieldTag {
226            __request_method,
227            __request_url,
228            __request_size,
229            __status,
230            __response_size,
231            __user_agent,
232            __remote_ip,
233            __server_ip,
234            __referer,
235            __latency,
236            __cache_lookup,
237            __cache_hit,
238            __cache_validated_with_origin_server,
239            __cache_fill_bytes,
240            __protocol,
241            Unknown(std::string::String),
242        }
243        impl<'de> serde::de::Deserialize<'de> for __FieldTag {
244            fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
245            where
246                D: serde::Deserializer<'de>,
247            {
248                struct Visitor;
249                impl<'de> serde::de::Visitor<'de> for Visitor {
250                    type Value = __FieldTag;
251                    fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
252                        formatter.write_str("a field name for HttpRequest")
253                    }
254                    fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
255                    where
256                        E: serde::de::Error,
257                    {
258                        use std::result::Result::Ok;
259                        use std::string::ToString;
260                        match value {
261                            "requestMethod" => Ok(__FieldTag::__request_method),
262                            "request_method" => Ok(__FieldTag::__request_method),
263                            "requestUrl" => Ok(__FieldTag::__request_url),
264                            "request_url" => Ok(__FieldTag::__request_url),
265                            "requestSize" => Ok(__FieldTag::__request_size),
266                            "request_size" => Ok(__FieldTag::__request_size),
267                            "status" => Ok(__FieldTag::__status),
268                            "responseSize" => Ok(__FieldTag::__response_size),
269                            "response_size" => Ok(__FieldTag::__response_size),
270                            "userAgent" => Ok(__FieldTag::__user_agent),
271                            "user_agent" => Ok(__FieldTag::__user_agent),
272                            "remoteIp" => Ok(__FieldTag::__remote_ip),
273                            "remote_ip" => Ok(__FieldTag::__remote_ip),
274                            "serverIp" => Ok(__FieldTag::__server_ip),
275                            "server_ip" => Ok(__FieldTag::__server_ip),
276                            "referer" => Ok(__FieldTag::__referer),
277                            "latency" => Ok(__FieldTag::__latency),
278                            "cacheLookup" => Ok(__FieldTag::__cache_lookup),
279                            "cache_lookup" => Ok(__FieldTag::__cache_lookup),
280                            "cacheHit" => Ok(__FieldTag::__cache_hit),
281                            "cache_hit" => Ok(__FieldTag::__cache_hit),
282                            "cacheValidatedWithOriginServer" => {
283                                Ok(__FieldTag::__cache_validated_with_origin_server)
284                            }
285                            "cache_validated_with_origin_server" => {
286                                Ok(__FieldTag::__cache_validated_with_origin_server)
287                            }
288                            "cacheFillBytes" => Ok(__FieldTag::__cache_fill_bytes),
289                            "cache_fill_bytes" => Ok(__FieldTag::__cache_fill_bytes),
290                            "protocol" => Ok(__FieldTag::__protocol),
291                            _ => Ok(__FieldTag::Unknown(value.to_string())),
292                        }
293                    }
294                }
295                deserializer.deserialize_identifier(Visitor)
296            }
297        }
298        struct Visitor;
299        impl<'de> serde::de::Visitor<'de> for Visitor {
300            type Value = HttpRequest;
301            fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
302                formatter.write_str("struct HttpRequest")
303            }
304            fn visit_map<A>(self, mut map: A) -> std::result::Result<Self::Value, A::Error>
305            where
306                A: serde::de::MapAccess<'de>,
307            {
308                #[allow(unused_imports)]
309                use serde::de::Error;
310                use std::option::Option::Some;
311                let mut fields = std::collections::HashSet::new();
312                let mut result = Self::Value::new();
313                while let Some(tag) = map.next_key::<__FieldTag>()? {
314                    #[allow(clippy::match_single_binding)]
315                    match tag {
316                        __FieldTag::__request_method => {
317                            if !fields.insert(__FieldTag::__request_method) {
318                                return std::result::Result::Err(A::Error::duplicate_field(
319                                    "multiple values for request_method",
320                                ));
321                            }
322                            result.request_method = map
323                                .next_value::<std::option::Option<std::string::String>>()?
324                                .unwrap_or_default();
325                        }
326                        __FieldTag::__request_url => {
327                            if !fields.insert(__FieldTag::__request_url) {
328                                return std::result::Result::Err(A::Error::duplicate_field(
329                                    "multiple values for request_url",
330                                ));
331                            }
332                            result.request_url = map
333                                .next_value::<std::option::Option<std::string::String>>()?
334                                .unwrap_or_default();
335                        }
336                        __FieldTag::__request_size => {
337                            if !fields.insert(__FieldTag::__request_size) {
338                                return std::result::Result::Err(A::Error::duplicate_field(
339                                    "multiple values for request_size",
340                                ));
341                            }
342                            struct __With(std::option::Option<i64>);
343                            impl<'de> serde::de::Deserialize<'de> for __With {
344                                fn deserialize<D>(
345                                    deserializer: D,
346                                ) -> std::result::Result<Self, D::Error>
347                                where
348                                    D: serde::de::Deserializer<'de>,
349                                {
350                                    serde_with::As::< std::option::Option<wkt::internal::I64> >::deserialize(deserializer).map(__With)
351                                }
352                            }
353                            result.request_size = map.next_value::<__With>()?.0.unwrap_or_default();
354                        }
355                        __FieldTag::__status => {
356                            if !fields.insert(__FieldTag::__status) {
357                                return std::result::Result::Err(A::Error::duplicate_field(
358                                    "multiple values for status",
359                                ));
360                            }
361                            struct __With(std::option::Option<i32>);
362                            impl<'de> serde::de::Deserialize<'de> for __With {
363                                fn deserialize<D>(
364                                    deserializer: D,
365                                ) -> std::result::Result<Self, D::Error>
366                                where
367                                    D: serde::de::Deserializer<'de>,
368                                {
369                                    serde_with::As::< std::option::Option<wkt::internal::I32> >::deserialize(deserializer).map(__With)
370                                }
371                            }
372                            result.status = map.next_value::<__With>()?.0.unwrap_or_default();
373                        }
374                        __FieldTag::__response_size => {
375                            if !fields.insert(__FieldTag::__response_size) {
376                                return std::result::Result::Err(A::Error::duplicate_field(
377                                    "multiple values for response_size",
378                                ));
379                            }
380                            struct __With(std::option::Option<i64>);
381                            impl<'de> serde::de::Deserialize<'de> for __With {
382                                fn deserialize<D>(
383                                    deserializer: D,
384                                ) -> std::result::Result<Self, D::Error>
385                                where
386                                    D: serde::de::Deserializer<'de>,
387                                {
388                                    serde_with::As::< std::option::Option<wkt::internal::I64> >::deserialize(deserializer).map(__With)
389                                }
390                            }
391                            result.response_size =
392                                map.next_value::<__With>()?.0.unwrap_or_default();
393                        }
394                        __FieldTag::__user_agent => {
395                            if !fields.insert(__FieldTag::__user_agent) {
396                                return std::result::Result::Err(A::Error::duplicate_field(
397                                    "multiple values for user_agent",
398                                ));
399                            }
400                            result.user_agent = map
401                                .next_value::<std::option::Option<std::string::String>>()?
402                                .unwrap_or_default();
403                        }
404                        __FieldTag::__remote_ip => {
405                            if !fields.insert(__FieldTag::__remote_ip) {
406                                return std::result::Result::Err(A::Error::duplicate_field(
407                                    "multiple values for remote_ip",
408                                ));
409                            }
410                            result.remote_ip = map
411                                .next_value::<std::option::Option<std::string::String>>()?
412                                .unwrap_or_default();
413                        }
414                        __FieldTag::__server_ip => {
415                            if !fields.insert(__FieldTag::__server_ip) {
416                                return std::result::Result::Err(A::Error::duplicate_field(
417                                    "multiple values for server_ip",
418                                ));
419                            }
420                            result.server_ip = map
421                                .next_value::<std::option::Option<std::string::String>>()?
422                                .unwrap_or_default();
423                        }
424                        __FieldTag::__referer => {
425                            if !fields.insert(__FieldTag::__referer) {
426                                return std::result::Result::Err(A::Error::duplicate_field(
427                                    "multiple values for referer",
428                                ));
429                            }
430                            result.referer = map
431                                .next_value::<std::option::Option<std::string::String>>()?
432                                .unwrap_or_default();
433                        }
434                        __FieldTag::__latency => {
435                            if !fields.insert(__FieldTag::__latency) {
436                                return std::result::Result::Err(A::Error::duplicate_field(
437                                    "multiple values for latency",
438                                ));
439                            }
440                            result.latency =
441                                map.next_value::<std::option::Option<wkt::Duration>>()?;
442                        }
443                        __FieldTag::__cache_lookup => {
444                            if !fields.insert(__FieldTag::__cache_lookup) {
445                                return std::result::Result::Err(A::Error::duplicate_field(
446                                    "multiple values for cache_lookup",
447                                ));
448                            }
449                            result.cache_lookup = map
450                                .next_value::<std::option::Option<bool>>()?
451                                .unwrap_or_default();
452                        }
453                        __FieldTag::__cache_hit => {
454                            if !fields.insert(__FieldTag::__cache_hit) {
455                                return std::result::Result::Err(A::Error::duplicate_field(
456                                    "multiple values for cache_hit",
457                                ));
458                            }
459                            result.cache_hit = map
460                                .next_value::<std::option::Option<bool>>()?
461                                .unwrap_or_default();
462                        }
463                        __FieldTag::__cache_validated_with_origin_server => {
464                            if !fields.insert(__FieldTag::__cache_validated_with_origin_server) {
465                                return std::result::Result::Err(A::Error::duplicate_field(
466                                    "multiple values for cache_validated_with_origin_server",
467                                ));
468                            }
469                            result.cache_validated_with_origin_server = map
470                                .next_value::<std::option::Option<bool>>()?
471                                .unwrap_or_default();
472                        }
473                        __FieldTag::__cache_fill_bytes => {
474                            if !fields.insert(__FieldTag::__cache_fill_bytes) {
475                                return std::result::Result::Err(A::Error::duplicate_field(
476                                    "multiple values for cache_fill_bytes",
477                                ));
478                            }
479                            struct __With(std::option::Option<i64>);
480                            impl<'de> serde::de::Deserialize<'de> for __With {
481                                fn deserialize<D>(
482                                    deserializer: D,
483                                ) -> std::result::Result<Self, D::Error>
484                                where
485                                    D: serde::de::Deserializer<'de>,
486                                {
487                                    serde_with::As::< std::option::Option<wkt::internal::I64> >::deserialize(deserializer).map(__With)
488                                }
489                            }
490                            result.cache_fill_bytes =
491                                map.next_value::<__With>()?.0.unwrap_or_default();
492                        }
493                        __FieldTag::__protocol => {
494                            if !fields.insert(__FieldTag::__protocol) {
495                                return std::result::Result::Err(A::Error::duplicate_field(
496                                    "multiple values for protocol",
497                                ));
498                            }
499                            result.protocol = map
500                                .next_value::<std::option::Option<std::string::String>>()?
501                                .unwrap_or_default();
502                        }
503                        __FieldTag::Unknown(key) => {
504                            let value = map.next_value::<serde_json::Value>()?;
505                            result._unknown_fields.insert(key, value);
506                        }
507                    }
508                }
509                std::result::Result::Ok(result)
510            }
511        }
512        deserializer.deserialize_any(Visitor)
513    }
514}
515
516#[doc(hidden)]
517impl serde::ser::Serialize for HttpRequest {
518    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
519    where
520        S: serde::ser::Serializer,
521    {
522        use serde::ser::SerializeMap;
523        #[allow(unused_imports)]
524        use std::option::Option::Some;
525        let mut state = serializer.serialize_map(std::option::Option::None)?;
526        if !self.request_method.is_empty() {
527            state.serialize_entry("requestMethod", &self.request_method)?;
528        }
529        if !self.request_url.is_empty() {
530            state.serialize_entry("requestUrl", &self.request_url)?;
531        }
532        if !wkt::internal::is_default(&self.request_size) {
533            struct __With<'a>(&'a i64);
534            impl<'a> serde::ser::Serialize for __With<'a> {
535                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
536                where
537                    S: serde::ser::Serializer,
538                {
539                    serde_with::As::<wkt::internal::I64>::serialize(self.0, serializer)
540                }
541            }
542            state.serialize_entry("requestSize", &__With(&self.request_size))?;
543        }
544        if !wkt::internal::is_default(&self.status) {
545            struct __With<'a>(&'a i32);
546            impl<'a> serde::ser::Serialize for __With<'a> {
547                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
548                where
549                    S: serde::ser::Serializer,
550                {
551                    serde_with::As::<wkt::internal::I32>::serialize(self.0, serializer)
552                }
553            }
554            state.serialize_entry("status", &__With(&self.status))?;
555        }
556        if !wkt::internal::is_default(&self.response_size) {
557            struct __With<'a>(&'a i64);
558            impl<'a> serde::ser::Serialize for __With<'a> {
559                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
560                where
561                    S: serde::ser::Serializer,
562                {
563                    serde_with::As::<wkt::internal::I64>::serialize(self.0, serializer)
564                }
565            }
566            state.serialize_entry("responseSize", &__With(&self.response_size))?;
567        }
568        if !self.user_agent.is_empty() {
569            state.serialize_entry("userAgent", &self.user_agent)?;
570        }
571        if !self.remote_ip.is_empty() {
572            state.serialize_entry("remoteIp", &self.remote_ip)?;
573        }
574        if !self.server_ip.is_empty() {
575            state.serialize_entry("serverIp", &self.server_ip)?;
576        }
577        if !self.referer.is_empty() {
578            state.serialize_entry("referer", &self.referer)?;
579        }
580        if self.latency.is_some() {
581            state.serialize_entry("latency", &self.latency)?;
582        }
583        if !wkt::internal::is_default(&self.cache_lookup) {
584            state.serialize_entry("cacheLookup", &self.cache_lookup)?;
585        }
586        if !wkt::internal::is_default(&self.cache_hit) {
587            state.serialize_entry("cacheHit", &self.cache_hit)?;
588        }
589        if !wkt::internal::is_default(&self.cache_validated_with_origin_server) {
590            state.serialize_entry(
591                "cacheValidatedWithOriginServer",
592                &self.cache_validated_with_origin_server,
593            )?;
594        }
595        if !wkt::internal::is_default(&self.cache_fill_bytes) {
596            struct __With<'a>(&'a i64);
597            impl<'a> serde::ser::Serialize for __With<'a> {
598                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
599                where
600                    S: serde::ser::Serializer,
601                {
602                    serde_with::As::<wkt::internal::I64>::serialize(self.0, serializer)
603                }
604            }
605            state.serialize_entry("cacheFillBytes", &__With(&self.cache_fill_bytes))?;
606        }
607        if !self.protocol.is_empty() {
608            state.serialize_entry("protocol", &self.protocol)?;
609        }
610        if !self._unknown_fields.is_empty() {
611            for (key, value) in self._unknown_fields.iter() {
612                state.serialize_entry(key, &value)?;
613            }
614        }
615        state.end()
616    }
617}
618
619/// The severity of the event described in a log entry, expressed as one of the
620/// standard severity levels listed below.  For your reference, the levels are
621/// assigned the listed numeric values. The effect of using numeric values other
622/// than those listed is undefined.
623///
624/// You can filter for log entries by severity.  For example, the following
625/// filter expression will match log entries with severities `INFO`, `NOTICE`,
626/// and `WARNING`:
627///
628/// ```norust
629/// severity > DEBUG AND severity <= WARNING
630/// ```
631///
632/// If you are writing log entries, you should map other severity encodings to
633/// one of these standard levels. For example, you might map all of Java's FINE,
634/// FINER, and FINEST levels to `LogSeverity.DEBUG`. You can preserve the
635/// original severity level in the log entry payload if you wish.
636///
637/// # Working with unknown values
638///
639/// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
640/// additional enum variants at any time. Adding new variants is not considered
641/// a breaking change. Applications should write their code in anticipation of:
642///
643/// - New values appearing in future releases of the client library, **and**
644/// - New values received dynamically, without application changes.
645///
646/// Please consult the [Working with enums] section in the user guide for some
647/// guidelines.
648///
649/// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
650#[derive(Clone, Debug, PartialEq)]
651#[non_exhaustive]
652pub enum LogSeverity {
653    /// (0) The log entry has no assigned severity level.
654    Default,
655    /// (100) Debug or trace information.
656    Debug,
657    /// (200) Routine information, such as ongoing status or performance.
658    Info,
659    /// (300) Normal but significant events, such as start up, shut down, or
660    /// a configuration change.
661    Notice,
662    /// (400) Warning events might cause problems.
663    Warning,
664    /// (500) Error events are likely to cause problems.
665    Error,
666    /// (600) Critical events cause more severe problems or outages.
667    Critical,
668    /// (700) A person must take an action immediately.
669    Alert,
670    /// (800) One or more systems are unusable.
671    Emergency,
672    /// If set, the enum was initialized with an unknown value.
673    ///
674    /// Applications can examine the value using [LogSeverity::value] or
675    /// [LogSeverity::name].
676    UnknownValue(log_severity::UnknownValue),
677}
678
679#[doc(hidden)]
680pub mod log_severity {
681    #[allow(unused_imports)]
682    use super::*;
683    #[derive(Clone, Debug, PartialEq)]
684    pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
685}
686
687impl LogSeverity {
688    /// Gets the enum value.
689    ///
690    /// Returns `None` if the enum contains an unknown value deserialized from
691    /// the string representation of enums.
692    pub fn value(&self) -> std::option::Option<i32> {
693        match self {
694            Self::Default => std::option::Option::Some(0),
695            Self::Debug => std::option::Option::Some(100),
696            Self::Info => std::option::Option::Some(200),
697            Self::Notice => std::option::Option::Some(300),
698            Self::Warning => std::option::Option::Some(400),
699            Self::Error => std::option::Option::Some(500),
700            Self::Critical => std::option::Option::Some(600),
701            Self::Alert => std::option::Option::Some(700),
702            Self::Emergency => std::option::Option::Some(800),
703            Self::UnknownValue(u) => u.0.value(),
704        }
705    }
706
707    /// Gets the enum value as a string.
708    ///
709    /// Returns `None` if the enum contains an unknown value deserialized from
710    /// the integer representation of enums.
711    pub fn name(&self) -> std::option::Option<&str> {
712        match self {
713            Self::Default => std::option::Option::Some("DEFAULT"),
714            Self::Debug => std::option::Option::Some("DEBUG"),
715            Self::Info => std::option::Option::Some("INFO"),
716            Self::Notice => std::option::Option::Some("NOTICE"),
717            Self::Warning => std::option::Option::Some("WARNING"),
718            Self::Error => std::option::Option::Some("ERROR"),
719            Self::Critical => std::option::Option::Some("CRITICAL"),
720            Self::Alert => std::option::Option::Some("ALERT"),
721            Self::Emergency => std::option::Option::Some("EMERGENCY"),
722            Self::UnknownValue(u) => u.0.name(),
723        }
724    }
725}
726
727impl std::default::Default for LogSeverity {
728    fn default() -> Self {
729        use std::convert::From;
730        Self::from(0)
731    }
732}
733
734impl std::fmt::Display for LogSeverity {
735    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
736        wkt::internal::display_enum(f, self.name(), self.value())
737    }
738}
739
740impl std::convert::From<i32> for LogSeverity {
741    fn from(value: i32) -> Self {
742        match value {
743            0 => Self::Default,
744            100 => Self::Debug,
745            200 => Self::Info,
746            300 => Self::Notice,
747            400 => Self::Warning,
748            500 => Self::Error,
749            600 => Self::Critical,
750            700 => Self::Alert,
751            800 => Self::Emergency,
752            _ => Self::UnknownValue(log_severity::UnknownValue(
753                wkt::internal::UnknownEnumValue::Integer(value),
754            )),
755        }
756    }
757}
758
759impl std::convert::From<&str> for LogSeverity {
760    fn from(value: &str) -> Self {
761        use std::string::ToString;
762        match value {
763            "DEFAULT" => Self::Default,
764            "DEBUG" => Self::Debug,
765            "INFO" => Self::Info,
766            "NOTICE" => Self::Notice,
767            "WARNING" => Self::Warning,
768            "ERROR" => Self::Error,
769            "CRITICAL" => Self::Critical,
770            "ALERT" => Self::Alert,
771            "EMERGENCY" => Self::Emergency,
772            _ => Self::UnknownValue(log_severity::UnknownValue(
773                wkt::internal::UnknownEnumValue::String(value.to_string()),
774            )),
775        }
776    }
777}
778
779impl serde::ser::Serialize for LogSeverity {
780    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
781    where
782        S: serde::Serializer,
783    {
784        match self {
785            Self::Default => serializer.serialize_i32(0),
786            Self::Debug => serializer.serialize_i32(100),
787            Self::Info => serializer.serialize_i32(200),
788            Self::Notice => serializer.serialize_i32(300),
789            Self::Warning => serializer.serialize_i32(400),
790            Self::Error => serializer.serialize_i32(500),
791            Self::Critical => serializer.serialize_i32(600),
792            Self::Alert => serializer.serialize_i32(700),
793            Self::Emergency => serializer.serialize_i32(800),
794            Self::UnknownValue(u) => u.0.serialize(serializer),
795        }
796    }
797}
798
799impl<'de> serde::de::Deserialize<'de> for LogSeverity {
800    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
801    where
802        D: serde::Deserializer<'de>,
803    {
804        deserializer.deserialize_any(wkt::internal::EnumVisitor::<LogSeverity>::new(
805            ".google.logging.type.LogSeverity",
806        ))
807    }
808}