liblog: Virtual stream for logging
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
All this stuff is under GNU General Public License 3. Have fun ! ;p
First, clone the project and then
cd into the library directory. Then, you will have to configure and then install.
./configure --fx9860g make && make install
./configure --fxcg50 make && make install
Now, you have installed the library in your compiler. You can now use it in projects.
Note: the library can be installed for both platforms at the same time, installing one will not overwrite the other build.
We'll see how tu use the library in a sample 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
# 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-cg to the lines. Once it is modified it should be like this:
# 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
Before using it, you have to write at the beginning of your source file:
To initialize or reset the log, use
log_clear() function, for example in main.c.
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_FATAL The print function is easy to use:
ll_send(priority, "Your text");
For example, I want to send a warning because a file doesn't exist, I just have to write:
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
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
If you don't use priority, the only level you use is LEVEL_INFO, so to restart it, use ll_set_level(LEVEL_INFO); ;)
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
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.