@@ -38,6 +38,10 @@ pub struct ResolvedRuntimeConfig<T> {
38
38
///
39
39
/// `None` is used for an "unset" state directory which each factor will treat differently.
40
40
pub state_dir : Option < PathBuf > ,
41
+ /// The fully resolved log directory.
42
+ ///
43
+ /// `None` is used for an "unset" log directory.
44
+ pub log_dir : Option < PathBuf > ,
41
45
}
42
46
43
47
impl < T > ResolvedRuntimeConfig < T >
@@ -49,13 +53,23 @@ where
49
53
pub fn from_optional_file (
50
54
runtime_config_path : Option < & Path > ,
51
55
provided_state_dir : Option < & Path > ,
56
+ provided_log_dir : LogDir ,
52
57
use_gpu : bool ,
53
58
) -> anyhow:: Result < Self > {
54
59
match runtime_config_path {
55
- Some ( runtime_config_path) => {
56
- Self :: from_file ( runtime_config_path, provided_state_dir, use_gpu)
57
- }
58
- None => Self :: new ( Default :: default ( ) , None , provided_state_dir, use_gpu) ,
60
+ Some ( runtime_config_path) => Self :: from_file (
61
+ runtime_config_path,
62
+ provided_state_dir,
63
+ provided_log_dir,
64
+ use_gpu,
65
+ ) ,
66
+ None => Self :: new (
67
+ Default :: default ( ) ,
68
+ None ,
69
+ provided_state_dir,
70
+ provided_log_dir,
71
+ use_gpu,
72
+ ) ,
59
73
}
60
74
}
61
75
65
79
pub fn from_file (
66
80
runtime_config_path : & Path ,
67
81
provided_state_dir : Option < & Path > ,
82
+ provided_log_dir : LogDir ,
68
83
use_gpu : bool ,
69
84
) -> anyhow:: Result < Self > {
70
85
let file = std:: fs:: read_to_string ( runtime_config_path) . with_context ( || {
@@ -80,17 +95,24 @@ where
80
95
)
81
96
} ) ?;
82
97
83
- Self :: new ( toml, Some ( runtime_config_path) , provided_state_dir, use_gpu)
98
+ Self :: new (
99
+ toml,
100
+ Some ( runtime_config_path) ,
101
+ provided_state_dir,
102
+ provided_log_dir,
103
+ use_gpu,
104
+ )
84
105
}
85
106
86
107
/// Creates a new resolved runtime configuration from a TOML table.
87
108
pub fn new (
88
109
toml : toml:: Table ,
89
110
runtime_config_path : Option < & Path > ,
90
111
provided_state_dir : Option < & Path > ,
112
+ provided_log_dir : LogDir ,
91
113
use_gpu : bool ,
92
114
) -> anyhow:: Result < Self > {
93
- let toml_resolver = TomlResolver :: new ( & toml, provided_state_dir) ;
115
+ let toml_resolver = TomlResolver :: new ( & toml, provided_state_dir, provided_log_dir ) ;
94
116
let tls_resolver = runtime_config_path. map ( SpinTlsRuntimeConfig :: new) ;
95
117
let key_value_config_resolver = key_value_config_resolver ( toml_resolver. state_dir ( ) ?) ;
96
118
let sqlite_config_resolver = sqlite_config_resolver ( toml_resolver. state_dir ( ) ?)
@@ -110,6 +132,7 @@ where
110
132
key_value_resolver : key_value_config_resolver,
111
133
sqlite_resolver : sqlite_config_resolver,
112
134
state_dir : toml_resolver. state_dir ( ) ?,
135
+ log_dir : toml_resolver. log_dir ( ) ?,
113
136
} )
114
137
}
115
138
@@ -144,6 +167,11 @@ where
144
167
pub fn state_dir ( & self ) -> Option < PathBuf > {
145
168
self . state_dir . clone ( )
146
169
}
170
+
171
+ /// The fully resolved state directory.
172
+ pub fn log_dir ( & self ) -> Option < PathBuf > {
173
+ self . log_dir . clone ( )
174
+ }
147
175
}
148
176
149
177
#[ derive( Clone , Debug ) ]
@@ -152,16 +180,19 @@ pub struct TomlResolver<'a> {
152
180
table : TomlKeyTracker < ' a > ,
153
181
/// Explicitly provided state directory.
154
182
state_dir : Option < & ' a Path > ,
183
+ /// Explicitly provided log directory.
184
+ log_dir : LogDir ,
155
185
}
156
186
157
187
impl < ' a > TomlResolver < ' a > {
158
188
/// Create a new TOML resolver.
159
189
///
160
190
/// The `state_dir` is the explicitly provided state directory, if any.
161
- pub fn new ( table : & ' a toml:: Table , state_dir : Option < & ' a Path > ) -> Self {
191
+ pub fn new ( table : & ' a toml:: Table , state_dir : Option < & ' a Path > , log_dir : LogDir ) -> Self {
162
192
Self {
163
193
table : TomlKeyTracker :: new ( table) ,
164
194
state_dir,
195
+ log_dir,
165
196
}
166
197
}
167
198
@@ -183,6 +214,17 @@ impl<'a> TomlResolver<'a> {
183
214
. transpose ( )
184
215
}
185
216
217
+ /// Get the configured log directory.
218
+ ///
219
+ /// Errors if the path cannot be converted to an absolute path.
220
+ pub fn log_dir ( & self ) -> std:: io:: Result < Option < PathBuf > > {
221
+ match & self . log_dir {
222
+ LogDir :: Provided ( p) => Ok ( Some ( std:: path:: absolute ( p) ?) ) ,
223
+ LogDir :: Default => Ok ( self . state_dir ( ) ?. map ( |p| p. join ( "logs" ) ) ) ,
224
+ LogDir :: None => Ok ( None ) ,
225
+ }
226
+ }
227
+
186
228
/// Validate that all keys in the TOML file have been used.
187
229
pub fn validate_all_keys_used ( & self ) -> spin_factors:: Result < ( ) > {
188
230
self . table . validate_all_keys_used ( )
@@ -354,3 +396,14 @@ fn sqlite_config_resolver(
354
396
local_database_dir,
355
397
) )
356
398
}
399
+
400
+ /// The log directory for the trigger.
401
+ #[ derive( Clone , Debug ) ]
402
+ pub enum LogDir {
403
+ /// Use the explicitly provided log directory.
404
+ Provided ( PathBuf ) ,
405
+ /// Use the default log directory.
406
+ Default ,
407
+ /// Do not log.
408
+ None ,
409
+ }
0 commit comments