Elog Tutorial: Add some Log (using)
Table of Contents
You might not use the log directly. The reson is simple:
- It is designed to be replaced by an other log library.
This permit you to use custom log library just replacing Macro and basic functions
Declaring the list of macro
debug.h
debug.cpp
#include "debug.hpp"
int32_t appl::getLogId() {
return g_val;
}
- on your main application:
#include "debug.hpp"
#include <elog/elog.hpp>
int main(int _argc, const char *_argv[]) {
// if you use etk/ewol/gale, elog init in contain in it.
elog::init(_argc, _argv);
Using it
You just need to call the macro whe you want to add debug log:
APPL_VERBOSE("VERBOSE display");
APPL_DEBUG("DEBUG display");
APPL_INFO("INFO display");
APPL_WARNING("WARNING display");
APPL_ERROR("ERROR display");
APPL_PRINT("PRINT display");
//APPL_CRITICAL("CRITICAL display"); // Disable critical because it create an assert ...
Specification of logs
- *_CRITICAL(***); This will log the data and asert just after (display backtrace if possible)
- *_PRINT(***); display on console (can not be removed with the log-level)
Log in an external logger
You must specify an external function that is receiving the logs:
static void myExternalLogCallback(const char* _libName, enum elog::level _level, int32_t _ligne, const char* _funcName, const char* _log) {
Now you must connect it on the elog backend:
// Set a callback:
elog::setCallbackLog(&myExternalLogCallback);
elog::setCallbackLog(&myExternalLogCallback);
The full code of the callback:
static void myExternalLogCallback(const char* _libName, enum elog::level _level, int32_t _ligne, const char* _funcName, const char* _log) {
switch(_level) {
default:
std::cout << "[?] ";
break;
case elog::level_print:
std::cout << "[P] ";
break;
case elog::level_critical:
std::cout << "[C] ";
break;
case elog::level_error:
std::cout << "[E] ";
break;
case elog::level_warning:
std::cout << "[W] ";
break;
case elog::level_info:
std::cout << "[I] ";
break;
case elog::level_debug:
std::cout << "[D] ";
break;
case elog::level_verbose:
std::cout << "[V] ";
break;
}
std::cout << _libName << " (" << _ligne << ") " << _funcName << " | " << _log << std::endl;
}
you can test the program: