flex-logger
This is a simple logger implementing the log crate interface.
- It is simple to initialize and use, and supports logging directly on the caller thread as well as on a separate thread.
- It supports logging with different timestamps format (utc/local)
- It supports tracing the thread id of the called as well.
- It supports logging on different targets (stdout/file) and the logging is buffered with a custom buffer size (which should make it faster to avoid a lot of locks on the resource in use.)
Note
The flush method of the log crate interface was implemented here as cleanup.
In other words, this call ensures that all the buffered logs are immediately flushed but destroys the logger.
Ensure to call this method only at the end of your program
Example
use ;
use Logger;
use ;
And here is the output of the program:
09:34:31:222312-[][main] -> {INFO} This is a info test
09:34:31:222400-[][main] -> {WARN} This is a warn test
09:34:31:222432-[][main] -> {ERROR} This is an error test
09:34:31:222551-[][main] -> {WARN} Warning on main!
09:34:31:222570-[][Thread 1] -> {INFO} This is a info, i: 0
09:34:31:222622-[][Thread 1] -> {INFO} This is a info, i: 1
09:34:31:222616-[][Thread 2] -> {INFO} This is a info, i: 0
09:34:31:222657-[][Thread 1] -> {INFO} This is a info, i: 2
09:34:31:222666-[][Thread 2] -> {INFO} This is a info, i: 1
09:34:31:222685-[][Thread 1] -> {INFO} This is a info, i: 3
09:34:31:222693-[][Thread 2] -> {INFO} This is a info, i: 2
09:34:31:222712-[][Thread 1] -> {INFO} This is a info, i: 4
09:34:31:222714-[][Thread 2] -> {INFO} This is a info, i: 3
09:34:31:222738-[][Thread 1] -> {INFO} This is a info, i: 5
09:34:31:222740-[][Thread 2] -> {INFO} This is a info, i: 4
09:34:31:222769-[][Thread 2] -> {INFO} This is a info, i: 5
09:34:31:222768-[][Thread 1] -> {INFO} This is a info, i: 6
09:34:31:222801-[][Thread 2] -> {INFO} This is a info, i: 6
09:34:31:222802-[][Thread 1] -> {INFO} This is a info, i: 7
09:34:31:222851-[][Thread 1] -> {INFO} This is a info, i: 8
09:34:31:222860-[][Thread 2] -> {INFO} This is a info, i: 7
09:34:31:222883-[][Thread 1] -> {INFO} This is a info, i: 9
09:34:31:222885-[][Thread 2] -> {INFO} This is a info, i: 8
09:34:31:222911-[][Thread 2] -> {INFO} This is a info, i: 9
In the examples directory you will find more examples.