[DEV] add a display of the backtrace if user request it
This commit is contained in:
parent
8494698338
commit
64bdda87d3
@ -75,10 +75,12 @@ void elog::init(int _argc, const char** _argv) {
|
||||
if (startWith(data, "--elog-level=")) {
|
||||
ELOG_INFO("Change global level at " << getLogLevel(std::string(data.begin()+13, data.end())));
|
||||
elog::setLevel(getLogLevel(std::string(data.begin()+13, data.end())));
|
||||
} else if (startWith(data, "--elog-color")) {
|
||||
} else if (data == "--elog-color") {
|
||||
elog::setColor(true);
|
||||
} else if (startWith(data, "--elog-no-color")) {
|
||||
} else if (data == "--elog-no-color") {
|
||||
elog::setColor(false);
|
||||
} else if (data == "--elog-back-trace") {
|
||||
elog::setBackTrace(true);
|
||||
} else if (startWith(data, "--elog-file=")) {
|
||||
std::string value(data.begin()+12, data.end());
|
||||
if (value.size() == 0) {
|
||||
@ -146,6 +148,7 @@ void elog::init(int _argc, const char** _argv) {
|
||||
ELOG_PRINT(" --elog-file=pathToFile File to store the logs: (disable console logs)");
|
||||
ELOG_PRINT(" --elog-color Enable color in log (default in Linux/debug)");
|
||||
ELOG_PRINT(" --elog-no-color Disable color in log (default in Linux/release and Other)");
|
||||
ELOG_PRINT(" --elog-back-trace Enable back-trace when an error log level is generated (to get a fast debug)");
|
||||
ELOG_PRINT(" --elog-config= Configure the Log interface");
|
||||
ELOG_PRINT(" t: diplay time");
|
||||
#ifdef ELOG_BUILD_ETHREAD
|
||||
|
19
elog/log.cpp
19
elog/log.cpp
@ -36,7 +36,7 @@
|
||||
void * trace[MAX_DEPTH];
|
||||
int stack_depth = backtrace(trace, MAX_DEPTH);
|
||||
|
||||
ELOG_ERROR("Back-trace : ");
|
||||
ELOG_PRINT("Back-trace : ");
|
||||
for (int32_t i = 1; i < stack_depth; i++) {
|
||||
Dl_info dlinfo;
|
||||
if(!dladdr(trace[i], &dlinfo)) {
|
||||
@ -49,8 +49,8 @@
|
||||
symname = demangled;
|
||||
}
|
||||
if (_removeElement <= 0) {
|
||||
ELOG_WARNING(" " << dlinfo.dli_fname << ": ");
|
||||
ELOG_ERROR(" " << symname);
|
||||
ELOG_PRINT(" " << dlinfo.dli_fname << ": ");
|
||||
ELOG_PRINT(" " << symname);
|
||||
}
|
||||
_removeElement--;
|
||||
if(demangled != nullptr) {
|
||||
@ -248,6 +248,14 @@ void elog::setLibName(bool _status) {
|
||||
getLibName() = _status;
|
||||
}
|
||||
|
||||
static bool& getDisplayBackTrace() {
|
||||
static bool g_val = false;
|
||||
return g_val;
|
||||
}
|
||||
void elog::setBackTrace(bool _status) {
|
||||
getDisplayBackTrace() = _status;
|
||||
}
|
||||
|
||||
static void getDisplayTime(char* data) {
|
||||
#ifdef __TARGET_OS__Android
|
||||
struct timeval now;
|
||||
@ -588,6 +596,11 @@ void elog::logChar(int32_t _id, int32_t _level, int32_t _ligne, const char* _fun
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(700));
|
||||
displayBacktrace(true, 2);
|
||||
}
|
||||
// Display backtrace to facilitate the error problems
|
||||
if ( _level == level_error
|
||||
&& getDisplayBackTrace() == true) {
|
||||
displayBacktrace(false, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,6 +102,11 @@ namespace elog {
|
||||
* @param[in] _status New value.
|
||||
*/
|
||||
void setLibName(bool _status);
|
||||
/**
|
||||
* @brief Set back-trace display on Error log enable or disable.
|
||||
* @param[in] _status New value.
|
||||
*/
|
||||
void setBackTrace(bool _status);
|
||||
/**
|
||||
* @brief Call log to display
|
||||
* @param[in] _id Id of the instance type
|
||||
|
Loading…
x
Reference in New Issue
Block a user