casual_logger
What a bother. I want to logging it without setting it. Not a product.
なんて面倒だ。 設定せず にロギングしたい。 製品じゃないし。
Example 1
You can copy and paste and use immediately.
コピー&ペーストしてすぐに使用できます。
Your code:
use Log;
Output ./default-2020-07-23.log.toml
automatically generated:
[]
= 'Hello, world!!'
Terminal:
casual_logger | Remove 0 log file(s).
| If you don't want this message, set `Log::set_opt(Opt::Release);`.
Example 2
Sometimes you want the logger to be quiet.
ロガーに静かにしていて欲しいときもありますね。
Your code:
//! There are 7 log levels.
//! ログレベルは7段階です。
use ;
Output ./default-2020-07-23.log.toml
automatically generated:
[]
= 'The bath temperature is 44 degrees.'
[]
= 'The refrigerator is empty.'
[]
= 'Where did you put my train pass?'
[]
= "I haven't set an alarm clock."
Terminal:
casual_logger | Remove 0 log file(s).
| If you don't want this message, set `Log::set_opt(Opt::Release);`.
thread 'main' panicked at 'I haven't set an alarm clock.', examples\example2.rs:16:5
stack backtrace:
0: backtrace::backtrace::trace_unsynchronized
...omitted...
Example 3
Is the log file TOML?
ログファイルはTOMLですか?
Your code:
//! TOML tables are typed maps.
//! TOMLのテーブルは型付きのマップだ。
use ;
Output ./today-s-plan-2020-07-23.log.toml
automatically generated:
[]
= 'ShoppingToday'
= -7000
= '''
Buy shelves in the near month.
Replace the washing machine after a few years.
近い月に棚。
数年後に洗濯機買い替え。
'''
= -40000
= 190000
= -53000
= [ -63_000, -4_000, -10_000 ]
Terminal:
casual_logger | Remove 0 log file(s).
| If you don't want this message, set `Log::set_opt(Opt::Release);`.
Example 4
When will the log file disappear?
ログファイルはいつ消えるの?
This is when someone execute Log::remove_old_logs();
.
By default, it keeps files up to 7 days old.
By file name, not by timestamp.
Log::remove_old_logs()
を実行したときです。
デフォルトで7日前の日付まで残ります。
タイムスタンプではなく、ファイル名によって。
Before test:
./default-2020-07-15.log.toml
./default-2020-07-16.log.toml
./default-2020-07-17.log.toml
./default-2020-07-18.log.toml
./default-2020-07-19.log.toml
./default-2020-07-20.log.toml
./default-2020-07-21.log.toml
./default-2020-07-22.log.toml
./default-2020-07-23.log.toml
Your code:
use Log;
Output ./default-2020-07-23.log.toml
automatically generated:
[]
= 'Hooray!'
Terminal:
casual_logger | Remove 9 log file(s).
| If you don't want this message, set `Log::set_opt(Opt::Release);`.
After test:
./default-2020-07-23.log.toml
Example 5
We do not recommend making it complicated.
複雑にすることはお勧めしません。
Your code:
//! Tables are easier to see if they are not nested.
//! テーブルは入れ子にしない方が見やすいです。
use ;
Output ./complex-toml-2020-07-23.log.toml
automatically generated:
[]
= "I'm in trouble."
[[]]
= false
= 'Kitchen'
[[]]
= 'Bath'
= false
[[]]
= false
= 'Toilet'
[]
= 1
= 2
= 1
Terminal:
casual_logger | Remove 0 log file(s).
| If you don't want this message, set `Log::set_opt(Opt::Release);`.
Example 6
What if someone else used 'casual_logger' in another library?
もし他のライブラリで誰かが 'casual_logger' を使っていたなら、
どうなるでしょうか?
Your code:
//! See how to override the settings.
//! 設定を上書きする方法を確認してください。
use ;
Output ./lesson1-2020-07-23.log.toml
automatically generated:
[]
= 'This is an Application.'
= '.log.toml'
= 'lesson1'
= 'Info'
= 2
Terminal:
casual_logger | Remove 0 log file(s).
| If you don't want this message, set `Log::set_opt(Opt::Release);`.
Quality policy
Fail faster and improve faster.
失敗するなら早い方がいい。
1. casual_logger is entry model
Don't know how to log well? That's right. Rest assured.
You can't find it even if You look it up because logging is ad hoc.
うまくログを取る方法が分かりませんか? ですよね。 安心してください。
調べても見つからないのはロギングが場当たり的だからです。
Some shoes don't fit your size. There are differences.
What makes loggers hard is finding the right one for the job.
自分のサイズに合わない靴もある程度の違いです。
ロガーを困難にするのは、その仕事に適したロガーを見つけることです。
More specifically, it is difficult to adjust.
casual_logger
aims to be a logger with almost inflexible.
もっと言えば、調整が難しいのです。
casual_logger
は、ほとんど調整できないロガーを目指します。
Since the hammer is fixed, please look for a nail that is easy to hit.
ハンマーの方を固定するので、叩きやすい釘を探してください。
" No settings, use immediately.
Used in one example, throw away. "
「 設定なし、すぐに使用。
エグザンプルを1つ終われば、捨てるだけです 」
- There is no configuration file.
設定ファイルはありません。 - Log files can only be placed in the working directory.
ログファイルは作業ディレクトリに置きます。 - Rotate log by date automatically.
ログファイルは日付で順繰りに作られます。 - Delete old log files. (semi-automatic)
半自動でログファイルを削除します。 - Write policy is one application, one log file.
書込み方針は、 1アプリケーション1ログファイル です。- Priority 1: First important log file.
優先順位1: 最初に重要指定したログ・ファイル。 - Priority 2: Last specified log file.
優先順位2: 最後に指定したログ・ファイル。
- Priority 1: First important log file.
- It is for those who want to learn while using it.
使いながら覚える人向けです。
2. Connect to the competition
When you see a tournament, you'll want to try it with an entry model.
大会を見たら、エントリーモデルでもあなたは試したくなる。
- If the log level is set to fatal, there will be little
performance degradation. Good luck.
ログレベルをファータルにしてしまえば性能劣化はあんまりない。 - While setting to
Opt::Release
,
No message is output to standard output or error output.
Because there is a possibility that it will be a foul at the competition.
Opt::Release
, に設定中は、
標準出力、エラー出力にメッセージを出しません。
大会で反則になる可能性があるからです。
3. Encourage you
You want to get more and more logs.
あなたは どんどん ログを取りたくなる。
- Human readable log. TOML does not spoil it.
人間が読めるログ。 TOMLはそれを台無しにしません。 - Write the log as a TOML table, it can be easily parsed.
ログをTOMLテーブルとして書き込みます。解析しやすいです。
Disclaim
- (1) In trade off for processing speed:
- Don't forget
Log::flush()
for logging to complete at end of program. Log::flush()
is a waiting time of 20 milli second or more before the logger ends.
- Don't forget
- (2) In trade off for ease of introduction:
- You can break the toml format. Do not validate.
- (3) In trade off for intelligence suggestion by text editor:
- It differs from the standard Rust log interface.
- (4) In trade off for not stopping running:
- If the log export fails, the error is ignored.
Tested environment
- OS:
Windows 10
. - Editor:
Visual studio code
.
At first, Overall view
Your code:
//! All features are described in one copy and paste.
//! すべての機能が1つのコピー&ペーストで説明されています。
use ;
Output ./tic-tac-toe-2020-07-23.log.toml
automatically generated:
[]
= '''
Hello, world!!
こんにちわ、世界!!
'''
[]
= "x is 100.\r\n"
[]
= '( 1)TRACE'
[]
= "( 2)trace-line\r\n"
[]
= '( 3)DEBUG'
[]
= "( 4)debug-line\r\n"
[]
= '( 5)INFO'
[]
= "( 6)info-line\r\n"
[]
= '( 7)NOTICE'
[]
= "( 8)notice-line\r\n"
[]
= '( 9)WARN'
[]
= "(10)warn-line\r\n"
[]
= '(11)ERROR'
[]
= "(12)error-line\r\n"
[]
= '(13)FATAL'
[]
= "(14)fatal-line\r\n"
[]
= '(7)Trace on (7)Trace.'
[]
= '(6)Debug on (7)Trace.'
[]
= '(5)Info on (7)Trace.'
[]
= '(4)Notice on (7)Trace.'
[]
= '(3)Warn on (7)Trace.'
[]
= '(2)Error on (7)Trace.'
[]
= '(1)Fatal on (7)Trace.'
[]
= '(6)Debug on (6)debug.'
[]
= '(5)Info on (6)debug.'
[]
= '(4)Notice on (6)debug.'
[]
= '(3)Warn on (6)debug.'
[]
= '(2)Error on (6)debug.'
[]
= '(1)Fatal on (6)debug.'
[]
= '(5)Info on (5)Info.'
[]
= '(4)Notice on (5)Info.'
[]
= '(3)Warn on (5)Info.'
[]
= '(2)Error on (5)Info.'
[]
= '(1)Fatal on (5)Info.'
[]
= '(4)Notice on (4)Notice.'
[]
= '(3)Warn on (4)Notice.'
[]
= '(2)Error on (4)Notice.'
[]
= '(1)Fatal on (4)Notice.'
[]
= '(3)Warn on (3)Warn.'
[]
= '(2)Error on (3)Warn.'
[]
= '(1)Fatal on (3)Warn.'
[]
= '(2)Error on (2)Error.'
[]
= '(1)Fatal on (2)Error.'
[]
= '(1)Fatal on (1)Fatal.'
[]
= 'ShoppingToday'
= 'A'
= -7000
= true
= '''
Buy shelves in the near month.
Replace the washing machine after a few years.
近い月に棚。
数年後に洗濯機買い替え。
'''
= -40000
= 190000
= 46.5
= -53000
= [ -63_000, -4_000, -10_000 ]
[]
= "I'm in trouble."
[[]]
= false
= 'Kitchen'
[[]]
= 'Bath'
= false
[[]]
= false
= 'Toilet'
[]
= 1
= 2
= 1
Terminal:
casual_logger | Remove 0 log file(s).
| If you don't want this message, set `Log::set_opt(Opt::Release);`.
It is designed to use Log::fatal()
as the first argument for panic!()
. It is the abnormal termination of the program. There is a waiting time.
At second, Description
Your code:
use ;
At the timing of the first writing, a file with a
time stamp in its name is automatically generated.
Example of Log file name:
ログ・ファイル名の例:
tic-tac-toe-2020-07-22.log.toml
1---------- 3--------
2----------
1 Prefix 3 Extention
接頭辞 拡張子
2 StartDate
開始日
File name
Part | Name | Description | Default |
---|---|---|---|
./ |
file path | Working directory | |
only. | |||
tic-tac-toe |
Prefix | Editable. | default |
-2020-07-22 |
StartDate | Auto generated. | |
.log.toml |
Extension | .log.toml or |
.log.toml |
.log . |
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.
.log
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.
Extension:
Enum | String | Description | Default |
---|---|---|---|
Log |
.log |
For logs that are too large | |
to be colored in the editor. | |||
LogToml |
.log.toml |
Toml format. | Default |
Your code:
Log rotation
Your code:
;
remove_old_logs;
set_retention_days
Example:
retention_days
is 2.- Today is 2020-07-12.
- Call
Log::remove_old_logs()
method. - 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.
Name | Description | Default |
---|---|---|
retention_days |
After this number of days, | 7 |
the file will be deleted. |
Log level
Your code:
;
set_level
Name | Description | Default |
---|---|---|
level |
Used to switch between | Trace |
write and non-write. |
Example:
- 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. |
Your code:
// Multi-line string.
// The suffix "ln" adds a newline at the end.
infoln;
// After explicitly checking the level.
if enabled
// The level is implicitly confirmed.
trace;
traceln;
debug;
debugln;
info;
infoln;
notice;
noticeln;
warn;
warnln;
error;
errorln;
fatal;
fatalln;
A piece of advice.
// Fatal is Panic! Can be used as the first argument of.
panic!;
Fatal returns a string so you can try to record a panic message.
However, the last log may not be written if the program exits first.
See also: Log::set_timeout_secs() method.
Your code:
// Wait for seconds logging to complete.
// By default it's set to 30 seconds,
// so you probably don't need to set it.
set_timeout_secs;
Usage of Table
Static method | Description |
---|---|
::default() |
Create a instance. |
Instance method | Description |
---|---|
.bool(key, value) |
Insert a boolean. |
.char(key, value) |
Insert a character. |
.float(key, value) |
Insert a float. |
.int(key, value) |
Insert a signed integer. |
.literal(key, value) |
Not enclose this value in |
quotation marks. | |
You can break the toml format. | |
Do not validate. | |
.str(key, value) |
Insert a string. |
Multi-line string are | |
output with multiple lines. | |
.sub_t(key, table) |
Insert a sub table. |
.uint(key, value) |
Insert a unsigned integer. |
Do not include spaces in the key. TOML collapses.
It is difficult to explain to beginners how to use TOML.
If you make a TOML that cannot be parsed literally,
please correct it.
Your code:
// TOML say a table. So-called map.
// Use table by '_t' suffix.
// TOMLのテーブルは、いわゆるマップです。
// '_t' を末尾に付けて、テーブルを使用します。
infoln_t;
Output:
[]
= """
The sky is from top to bottom!!
上から下まで空です!!\r\n
"""
= "fly in the sky."
= 2
= """
climb
a tall
tree.
"""
Don't forget flush for logging to complete at end of program
Your code:
// Wait for logging to complete or to timeout.
flush;
If you do not flush,
the program will exit before writing all the logs.
TODO
- Dogfooding.
- Japanese(Multi-byte string) support.
- More minimal.
- Remove deprecated features.
- 0.6.0
- Error handling check.
- Toml cover.
- Primitive type.
- Array.
- Dotted key support (Sub table only).
- Add '_important()' method.
Appendix
Customize method
Your code: main.rs
use ;
Usage: other.rs
use crate LogExt;