rustvello_core/
logging.rs1use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11#[non_exhaustive]
12pub enum LogFormat {
13 Text,
15 Json,
17}
18
19impl Default for LogFormat {
20 fn default() -> Self {
21 Self::Text
22 }
23}
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
27#[non_exhaustive]
28pub enum LogStream {
29 Stderr,
30 Stdout,
31}
32
33impl Default for LogStream {
34 fn default() -> Self {
35 Self::Stderr
36 }
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[non_exhaustive]
42pub struct LogConfig {
43 pub level: String,
45 pub format: LogFormat,
47 pub use_colors: Option<bool>,
49 pub compact_context: bool,
51 pub stream: LogStream,
53}
54
55impl Default for LogConfig {
56 fn default() -> Self {
57 Self {
58 level: "info".to_string(),
59 format: LogFormat::Text,
60 use_colors: None,
61 compact_context: true,
62 stream: LogStream::Stderr,
63 }
64 }
65}
66
67impl LogConfig {
68 pub fn from_app_fields(
70 level: &str,
71 format: LogFormat,
72 use_colors: Option<bool>,
73 compact_context: bool,
74 ) -> Self {
75 Self {
76 level: level.to_owned(),
77 format,
78 use_colors,
79 compact_context,
80 stream: LogStream::Stderr,
81 }
82 }
83}