Add tutorial

This commit is contained in:
Milang 2020-04-04 14:35:52 +02:00
parent 3a77ae114e
commit 073346f307
1 changed files with 63 additions and 34 deletions

View File

@ -1,48 +1,77 @@
# liblog
# liblog: Virtual stream for logging
Une lib de log simple d'utilisation nécéssitant gint.
L'utilisation est archi simple ! On envoie une chaine de caractères et c'est tout !
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
On peut si besoin afficher ce log en cas d'erreur, ou simplement pour consulter l'état d'éxécution du programme à un moment donné.
## 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
```
### fxcg50 models
``` bash
./configure --fxcg50
make && make install
```
Now, you have installed the library in your compiler. You can now use it in projects.
## Installation
*Note: the library can be installed for both platforms at the same time, installing one will not overwrite the other build.*
Il vous suffit de vous placer dans ce dossier et taper dans un terminal
``` sh
make
make install || sudo make install
## 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 :=
```
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
```
## Utilisation
### Configurer le projet
Dans le fichier project.cfg du projet, modifier la ligne suivante
``` sh
LDFLAGS =
```
Il suffit d'ajouter 2 nouveaux flags, comme ça
``` sh
LDFLAGS = -llog -lgint-fx
```
### Dans le code source
D'abord, il faut inclure le header de liblog
Before using it, you have to write at the beginning of your source file:
``` C
#include <liblog.h>
```
To initialize or reset the log, use `log_clear()` function, for example in main.c.
#### Écrire dans le log
### 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:
``` C
ll_log("Votre message de débug");
ll_send(priority, "Your text");
```
#### Afficher le log
Afficher le log peut être utile pour le débug, notamment en cas d'exception.
Il suffira de taper la commande suivante :
For example, I want to send a warning because a file doesn't exist, I just have to write:
``` C
ll_display();
// getkey(); si vous voulez mettre le programme en pause pour lire
ll_send(LEVEL_WARNING, "Can't read file %s (ErrCode=%d)", filename, code);
```
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.