pub struct Log { /* private fields */ }
Expand description
The main struct for the custom log
§Example
To use the custom log, you need to use 3 steps.
At first you will create a new Log
. (You can also create more than one log for different usage.)
Just to remind, dont forget to import the custom
use log_file::custom::*;
Then go on with the creating the Log
:
// create Log
let mut log = Log::new(true, ':');
The second step is to use it. In the following I just will show the different options:
// with context as String
log.add("Titel 1",String::from("Context 1"));
// with context as &str
log.add_str("Titel 2","Context 2");
If that is done, you can finaly save the log in the end. Here an example for this step:
// save log
log.save("log.txt");
And now you are done. Now, every time you run your project, the new log will overwrite the existing one, if the file name dosn’t change.
Implementations§
Source§impl Log
impl Log
Sourcepub fn add(&mut self, titel: &str, context: String)
pub fn add(&mut self, titel: &str, context: String)
adding an element to this log with context as String
§Example
let mut example = Log::new(true, ':'));
example.add("Test",String::from("Hello, world!"));
Sourcepub fn add_str(&mut self, titel: &str, context: &str)
pub fn add_str(&mut self, titel: &str, context: &str)
adding an element to this log with context as &str
§Example
let mut example = Log::new(true, ':'));
example.add_str("Test","Hello, world!");
Sourcepub fn save(&self, file_name: &str)
pub fn save(&self, file_name: &str)
saves the log in file_name
Creates file if it does not exist and overwrites it if it does exist.
§Note
You have to give the whole file name as parameter. For example foo.txt
. If you just give foo
as file name, it will create a file without file type.
§Example
use log_file::default_code::Log;
fn main() {
let example = Log::new(true, String::from(":"));
example.save("foo.txt");
}