CClarify is a small framework for creating advanced logging system. It can write to your custom descriptor, pointing to buffer, and can save everything to file, if you set it to do so.
- Download main header cclarify.h
- Include it to your source file, where you want to add logging
- Now you should set up everything.
GLOBAL_INIT(); // Init logger variables
Clarifier clar; // Create logger object
// If you have int descriptor like stdout
init_loggerd(clar, descriptor);
// If you want it to write logs to file
init_loggerf(clar, fd);
// If you want it to write logs to both destinations
init_loggerfd(clar, descriptor, fd);
- You are good to go now!
If you want to assign some value to variable (custom types are not supported) you should do this:
ASSIGN(clar, variable, value);
It will output something like:
==> Assigning value "value" to "variable", old value: "old_var_val"
If you wanna execute some function, and signal if function started or stopped, do this:
EXEC(clar, function());
It will notify you about started execution:
==> Starting execution of function "function()"
And about end of function execution.
==> Execution of function "function()" finished
To display some king of message, you need just to use MSG() function.
// To display green info message, do this
MSG(clar, "Hello World!", INFO);
// Yellow - warning
MSG(clar, "Warning", WARNING);
// Red - error
MSG(clar, "Error", ERROR);
Sometimes you want just to display variable value. Do this:
DISPLAY(clar, variable);
and you will get something like:
==> Variable "variable" value: "420"
In last update i've added wrappers for some glibc functions, like malloc. You can enable my variant of them by passing --wrap=func
to linker. Currently available functions:
- malloc()
- calloc()
- realloc()
- free()
- fopen()
- fread()
- fwrite()