@@ -25,6 +25,24 @@ pub(crate) fn project_dirs() -> Option<ProjectDirs> {
2525 ProjectDirs :: from ( "" , "" , "djls" )
2626}
2727
28+ /// Get the log directory for the application and ensure it exists.
29+ ///
30+ /// Returns the XDG cache directory (e.g., ~/.cache/djls on Linux) if available,
31+ /// otherwise falls back to /tmp. Creates the directory if it doesn't exist.
32+ ///
33+ /// # Errors
34+ ///
35+ /// Returns an error if the directory cannot be created.
36+ pub fn log_dir ( ) -> anyhow:: Result < Utf8PathBuf > {
37+ let dir = project_dirs ( )
38+ . and_then ( |proj_dirs| Utf8PathBuf :: from_path_buf ( proj_dirs. cache_dir ( ) . to_path_buf ( ) ) . ok ( ) )
39+ . unwrap_or_else ( || Utf8PathBuf :: from ( "/tmp" ) ) ;
40+
41+ fs:: create_dir_all ( & dir) . with_context ( || format ! ( "Failed to create log directory: {dir}" ) ) ?;
42+
43+ Ok ( dir)
44+ }
45+
2846#[ derive( Error , Debug ) ]
2947pub enum ConfigError {
3048 #[ error( "Configuration build/deserialize error" ) ]
@@ -142,24 +160,6 @@ impl Settings {
142160 }
143161}
144162
145- /// Get the log directory for the application and ensure it exists.
146- ///
147- /// Returns the XDG cache directory (e.g., ~/.cache/djls on Linux) if available,
148- /// otherwise falls back to /tmp. Creates the directory if it doesn't exist.
149- ///
150- /// # Errors
151- ///
152- /// Returns an error if the directory cannot be created.
153- pub fn log_dir ( ) -> anyhow:: Result < Utf8PathBuf > {
154- let dir = project_dirs ( )
155- . and_then ( |proj_dirs| Utf8PathBuf :: from_path_buf ( proj_dirs. cache_dir ( ) . to_path_buf ( ) ) . ok ( ) )
156- . unwrap_or_else ( || Utf8PathBuf :: from ( "/tmp" ) ) ;
157-
158- fs:: create_dir_all ( & dir) . with_context ( || format ! ( "Failed to create log directory: {dir}" ) ) ?;
159-
160- Ok ( dir)
161- }
162-
163163#[ cfg( test) ]
164164mod tests {
165165 use std:: fs;
0 commit comments