casual_logger
This logger used when practicing the example programs.
Only write to file, rotate by date.
Not for hard users.
At first, Disclaim
- It differs from the standard Rust log interface.
- Ignore performance for ease of use.
At second, Overall view
Your code:
use ;
Output ./default-2020-07-12.log.toml
auto generated:
[]
= "Remove 0 files.\r\n"
[]
= """
Hello, world!!
こんにちわ、世界!!\r\n
"""
[]
= "x is 100.\r\n"
[]
= """
The sky is from top to bottom!!
上から下まで空です!!\r\n
"""
= "fly in the sky."
= """
climb
a tall
tree.
"""
= "swim."
[]
= "A,"
[]
= "B,\r\n"
[]
= "C,"
[]
= "D,\r\n"
[]
= "E,"
[]
= "F,\r\n"
[]
= "G,"
[]
= "H,\r\n"
[]
= "I,"
[]
= "J,\r\n"
[]
= "K,"
[]
= "L,\r\n"
[]
= "M,"
[]
= "N!\r\n"
At third, Description
Code:
use ;
At the timing of the first writing, a file with a
time stamp in its name is automatically generated.
For example: ./tic-tac-toe-2020-07-12.log.toml
Description:
Part | Name | Description | Default |
---|---|---|---|
./ |
file path | Working directory | |
only. | |||
tic-tac-toe |
Prefix | Editable. | default |
-2020-07-12 |
StartDate | Auto generated. | |
.log |
Suffix | Editable. | .log |
.toml |
Extension | Editable. | .toml |
It is difficult to explain the file path for beginners.
Therefore, it does not move.
Excite yourself with a prefix.
StartDate is basically today.
If the rotation fails, it is the start date.
Suffix to be safe, include a word that
clearly states that you can delete the file.
If you don't like the .toml extension, leave
the suffix empty and the .log extension.
Set up, Code:
Log rotation, Code:
let remove_num = if let Ok = LOGGER.lock else ;
noticeln;
Logger Properties
Name | Description | Default |
---|---|---|
retention_days |
After this number of days, | 7 |
the file will be deleted. | ||
level |
Used to switch between | Trace |
write and non-write. |
Example of retention_days:
retention_days
is 2.- Today is 2020-07-12.
- The
./default-2020-07-09.log.toml
file will be deleted. - The
./default-2020-07-10.log.toml
remains. - Delete old files by date in filename.
Example of level:
- There are 7 log levels.
|Fatal< Error < Warn < Notice < Info < Debug <Trace|
|<-- Small ------------------------------ Large -->|
|<-- Concise -------------------------- Verbose -->|
|<-- Low Level --------------------- High level -->|
|<-- High priority --------------- Low priority -->|
Level | Examle of use. |
---|---|
Fatal |
If the program cannot continue. |
Error |
I didn't get the expected result, |
so I'll continue with the other method. | |
Warn |
It will be abnormal soon, |
but there is no problem and you can ignore it. | |
For example: | |
(1) He reported that it took longer to access | |
than expected. | |
(2) Report that capacity is approaching the limit. | |
Notice |
It must be enabled in the server production |
environment. | |
Record of passing important points correctly. | |
We are monitoring that it is working properly. | |
Info |
Report highlights. |
Everything that needs to be reported regularly in | |
the production environment. | |
Debug |
It should be in a place with many accidents. |
This level is disabled in production environments. | |
Leave it in the source and enable it for | |
troubleshooting. | |
Often, this is the production level of a desktop | |
operating environment. | |
Trace |
Not included in the distribution. |
Remove this level from the source after using it | |
for debugging. | |
If you want to find a bug in the program, | |
write a lot. |
Code:
// Multi-line string.
infoln;
// After explicitly checking the level.
if enabled
// Suffix '_t'. TOML say a table. So-called map.
infoln_t;
// The level is implicitly confirmed.
trace;
traceln;
debug;
debugln;
info;
infoln;
notice;
noticeln;
warn;
warnln;
error;
errorln;
fatal;
fatalln;
TODO
- Adding table items as toml.
- str.
- Other type...
- Spawn another thread for logging.
Tested environment
- OS:
Windows 10
. - Editor:
Visual studio code
.
Appendix
Customize method
Code: main.rs
use Log;
Usage: other.rs
use crate LogExt;