Starts the daemon process and initializes logging. Sets up daily log rotation and dual logging to both files and system journal. Creates required directories if they don't exist. # Errors Returns `LearnerdErrors` if: - Directory creation fails - Log initialization fails - Daemon process fails to start
(&self)
| 236 | /// - Log initialization fails |
| 237 | /// - Daemon process fails to start |
| 238 | pub fn start(&self) -> Result<()> { |
| 239 | // Ensure directories exist |
| 240 | fs::create_dir_all(&self.working_dir)?; |
| 241 | fs::create_dir_all(&self.log_dir)?; |
| 242 | |
| 243 | // Configure file logging |
| 244 | let file_appender = rolling::RollingFileAppender::builder() |
| 245 | .rotation(rolling::Rotation::DAILY) |
| 246 | .filename_prefix("learnerd") |
| 247 | .filename_suffix("log") |
| 248 | .build(&self.log_dir)?; |
| 249 | |
| 250 | // Create a file layer for file logging |
| 251 | let file_layer = tracing_subscriber::fmt::layer() |
| 252 | .with_writer(file_appender) |
| 253 | .with_ansi(false) |
| 254 | .with_thread_ids(true) |
| 255 | .with_target(true) |
| 256 | .with_file(true) |
| 257 | .with_line_number(true); |
| 258 | |
| 259 | // Create a stdout layer for systemd/journal capture |
| 260 | let stdout_layer = tracing_subscriber::fmt::layer().with_ansi(false).with_target(true); |
| 261 | |
| 262 | // Initialize both layers |
| 263 | tracing_subscriber::registry() |
| 264 | .with(file_layer) |
| 265 | .with(stdout_layer) |
| 266 | .with(EnvFilter::new("debug")) |
| 267 | .init(); |
| 268 | |
| 269 | info!("Starting learnerd daemon"); |
| 270 | debug!("Using config: {:?}", self); |
| 271 | |
| 272 | info!("Daemon started successfully"); |
| 273 | self.run() |
| 274 | } |
| 275 | |
| 276 | // TODO (autoparallel): this is actually never really able to be used at the moment. |
| 277 | /// Attempts to stop a running daemon process. |