A lightweight and cross-plateform library to handle stacktrace and logging in C99.
All examples are in examples
directory.
./bin/<debug|release>/examples/stacktrace_example
#include <ei/ei.h>
#include <stdlib.h>
bool foo(void *parameter) {
if (!parameter) {
ei_stacktrace_push_msg("Specified parameter is invalid");
return false;
}
return true;
}
bool bar(void *parameter) {
if (!foo(parameter)) {
ei_stacktrace_push_msg("foo failed :(");
return false;
}
return true;
}
/**
* output:
* bar failed ! (thread 140371337471744)
* Caused by: Specified parameter is invalid
* at foo (stacktrace_example.c:7)
* at bar (stacktrace_example.c:16)
* at main (stacktrace_example.c:31)
*/
int main() {
void *arg;
arg = NULL;
ei_init();
if (!bar(arg)) {
ei_stacktrace_push_msg("bar failed !");
}
ei_stacktrace_print();
ei_uninit();
return EXIT_SUCCESS;
}
./bin/<debug|release>/examples/logger_example
#include <ei/ei.h>
#include <stdlib.h>
int main() {
ei_init();
ei_logger_trace("Loading library...");
ei_logger_debug("Variable value is %d", 58);
ei_logger_info("User %s is now connected", "username");
ei_logger_warn("Loading time is consequently longer");
ei_logger_error("Invalid password");
ei_logger_fatal("Out of memory");
ei_uninit();
return EXIT_SUCCESS;
}
Output:
./build_debug.sh
./build_release.sh
./clean.sh
./build_release.sh && sudo ./install.sh
build_debug.bat
build_release.bat
clean.bat
build_release.bat && install.bat
Tested on:
- Windows x86
- Windows 64
- Ubuntu 14.04
- Ubuntu 16.04