Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- use std::fs;
- use std::fs::{File, OpenOptions};
- use std::io;
- use std::io::Result;
- use std::path::PathBuf;
- pub struct Logger {
- log_dir: PathBuf,
- fds: HashMap<String, File>,
- }
- impl Logger {
- fn get_file(&mut self, target: &str) -> Result<&mut File> {
- if let Some(fd) = self.fds.get_mut(target) {
- return Ok(fd);
- }
- let mut file_path = self.log_dir.clone();
- file_path.push(&format!("{}.txt", target));
- let fd = OpenOptions::new().append(true).open(file_path)?;
- self.fds.insert(target.to_owned(), fd);
- self.get_file(target)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement