Table of contents
Instalation
update Cargo.toml file
Add log_file
to your dependencies:
[dependencies]
log_file = "0.1.1"
import it
Import as much as you like from the log_file lib:
use log_file;
Example
Log types
- custom:
structure example (custom)
Here an example for log_file::custom
:
// import everything from the `custom` module
use *;
The log.txt
file then should contain the following text:
Programmer : SnefDen
crate name : log_file
crate version : 0.1.1
If the time stamp is on (let mut log = Log::new(true, ':');
), the result looks like this for example:
[0:0:0:100] Programmer : SnefDen
[0:0:0:250] crate name : log_file
[0:0:0:250] crate version : 0.1.1
So the structure is the following:
time(optional) title separator content
The time is written in the following format and started if the log is created:
s:ms:µs:ns
s = seconds
ms = milliseconds (0.001s)
µs = mikroseconds (0.001ms)
ns = nanoseconds (0.001µs)
second example (custom)
For this example we use the pythagorean_theorem method. Here is the implementation without log:
This time we don't create a new log. Instead we change our header, so that we can use an existing one (and don't forget to make it mutable).
At last we update the log, based on the steps in the pythagorean_theorem()
method. Now the method should look like this:
If we use this function in main()
, it looks like this:
use *;
The log.txt
file now contains the following text:
pythagorean_theorem - step 1 : a*a
pythagorean_theorem - step 2 : b*b
pythagorean_theorem - step 3 : (a_sq + b_sq) * (a_sq + b_sq)
Features
Requirements
None