liblog/README.md

80 lines
3.5 KiB
Markdown
Raw Permalink Normal View History

2020-04-04 14:35:52 +02:00
# liblog: Virtual stream for logging
2019-09-18 16:58:19 +02:00
2020-04-04 14:35:52 +02:00
This library has been written to provide a sample stream, like a simplified printf to make on calc debug easier. It uses gint, and it is compatible with fxcg50 & fx9860g models.
It currenlty supports:
- Virtual stream with custom priorities for messages
- Dynamic weight in ram (maximum 1Ko for fx9860g and maximum 4Ko for fxcg50)
- Basic display functions for the stream
- Function for exceptions
2019-09-18 17:44:47 +02:00
2020-04-04 14:40:52 +02:00
All this stuff is under GNU General Public License 3. Have fun ! ;p
2020-04-04 14:35:52 +02:00
## Install
First, clone the project and then `cd` into the library directory. Then, you will have to configure and then install.
### fx9860g models
``` bash
./configure --fx9860g
make && make install
2019-09-18 17:44:47 +02:00
```
2020-04-04 14:35:52 +02:00
### fxcg50 models
``` bash
./configure --fxcg50
make && make install
```
Now, you have installed the library in your compiler. You can now use it in projects.
2019-09-18 17:44:47 +02:00
2020-04-04 14:35:52 +02:00
*Note: the library can be installed for both platforms at the same time, installing one will not overwrite the other build.*
2019-09-18 17:44:47 +02:00
2020-04-04 14:35:52 +02:00
## Tutorial
We'll see how tu use the library in a sample project. :)
### Configure project
You have to link the library in the project so you can use it in compilation ;)
You just have to add one word in the `project.cfg` file:
``` make
# Libraries. Add one -l option for each library you are using, and also
# suitable -L options if you have library files in custom folders. To use
# fxlib, add libfx.a to the project directory and use "-L . -lfx".
LIBS_FX :=
LIBS_CG :=
2019-09-18 17:44:47 +02:00
```
2020-04-04 14:35:52 +02:00
Just add the word `-llog-fx` and `-llog-cg` to the lines. Once it is modified it should be like this:
``` make
# Libraries. Add one -l option for each library you are using, and also
# suitable -L options if you have library files in custom folders. To use
# fxlib, add libfx.a to the project directory and use "-L . -lfx".
LIBS_FX := -llog-fx
LIBS_CG := -llog-cg
2019-09-18 17:44:47 +02:00
```
2020-04-04 14:35:52 +02:00
Before using it, you have to write at the beginning of your source file:
2019-09-18 17:44:47 +02:00
``` C
#include <liblog.h>
```
2020-04-04 14:35:52 +02:00
To initialize or reset the log, use `log_clear()` function, for example in main.c.
2019-09-18 17:44:47 +02:00
2020-04-04 14:35:52 +02:00
### Write text
You can easily send text to the stream with `ll_send()`. However, you can set a priority to this message. The different priority levels are:
- LEVEL_INFO (if don't want to use the priorty levels, use it)
- LEVEL_WARNING
- LEVEL_CRITICAL
- LEVEL_FATAL
The print function is easy to use:
2019-09-18 17:44:47 +02:00
``` C
2020-04-04 14:35:52 +02:00
ll_send(priority, "Your text");
2019-09-18 17:44:47 +02:00
```
2020-04-04 14:35:52 +02:00
For example, I want to send a warning because a file doesn't exist, I just have to write:
2019-09-18 17:44:47 +02:00
``` C
2020-04-04 14:35:52 +02:00
ll_send(LEVEL_WARNING, "Can't read file %s (ErrCode=%d)", filename, code);
2019-09-18 17:44:47 +02:00
```
2020-04-04 14:35:52 +02:00
You can note that it uses the same syntax as printf, because it uses `sprintf()` from gint. So you can enter all the types or arguments that gint supports. :p
### Change priority
You can also set the mimimal priorty level that the log accepts with `void ll_set_level(log_level_t);`. You can suspend it with `ll_set_level(LEVEL_QUIET);`, and at any moment change the priority to reaccept new messages. You can also get the current priorty with `ll_get_level(void)`.
*If you don't use priority, the only level you use is LEVEL_INFO, so to restart it, use ll_set_level(LEVEL_INFO); ;)*
### Display log
Just call `ll_display()` to draw the last lines. It is a "one frame" function, there is no input management. To scroll, just use `ll_pause();` which allows to use the arrows to scroll. To get out this function, use the `[EXIT]` key.
### Enable panic function
You just have to run once `ll_set_panic();`. After this, if there is any "System Error", the log will be displayed and you could track the bug.