/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include <algorithm>
-#include <cctype>
-#include <cstdarg>
-#include <cstdio> /* snprintf */
-#include <cstdlib>
-#include <mutex>
-
-#include "src/internal_config.h"
-
#include "src/xbt_modinter.h"
-
#include "src/xbt/log_private.hpp"
#include "xbt/asserts.h"
#include "xbt/dynar.h"
-#include "xbt/ex.h"
-#include "xbt/misc.h"
#include "xbt/str.h"
-#include "xbt/sysdep.h"
+
+#include <mutex>
+#include <string>
int xbt_log_no_loc = 0; /* if set to true (with --log=no_loc), file localization will be omitted (for tesh tests) */
static std::recursive_mutex* log_cat_init_mutex = nullptr;
{
xbt_log_setting_t set = *(xbt_log_setting_t *) s;
if (set) {
- free(set->catname);
- free(set->fmt);
- free(set);
+ xbt_free(set->catname);
+ xbt_free(set->fmt);
+ xbt_free(set);
}
}
if (cat->appender) {
if (cat->appender->free_)
cat->appender->free_(cat->appender);
- free(cat->appender);
+ xbt_free(cat->appender);
}
if (cat->layout) {
if (cat->layout->free_)
cat->layout->free_(cat->layout);
- free(cat->layout);
+ xbt_free(cat->layout);
}
for (child = cat->firstChild; child != nullptr; child = child->nextSibling)
int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority)
{
DISABLE_XBT_LOG_CAT_INIT();
+ if (category->initialized)
+ return priority >= category->threshold;
+
if (log_cat_init_mutex != nullptr)
log_cat_init_mutex->lock();
- if (category->initialized) {
- if (log_cat_init_mutex != nullptr)
- log_cat_init_mutex->unlock();
- return priority >= category->threshold;
- }
-
unsigned int cursor;
xbt_log_setting_t setting = nullptr;
xbt_log_parent_set(category, category->parent);
if (XBT_LOG_ISENABLED(log, xbt_log_priority_debug)) {
- char *buf;
- char* res = nullptr;
+ std::string res;
xbt_log_category_t cpp = category->parent->firstChild;
while (cpp) {
- if (res) {
- buf = bprintf("%s %s", res, cpp->name);
- free(res);
- res = buf;
- } else {
- res = xbt_strdup(cpp->name);
- }
+ res += std::string(" ") + cpp->name;
cpp = cpp->nextSibling;
}
- XBT_DEBUG("Children of %s: %s; nextSibling: %s", category->parent->name, res,
- (category->parent->nextSibling ? category->parent->nextSibling->name : "none"));
-
- free(res);
+ XBT_DEBUG("Children of %s:%s; nextSibling: %s", category->parent->name, res.c_str(),
+ (category->parent->nextSibling ? category->parent->nextSibling->name : "none"));
}
}
THROWF(arg_error, 0,
"Unknown priority name: %s (must be one of: trace,debug,verbose,info,warning,error,critical)", eq + 1);
}
- free(neweq);
+ xbt_free(neweq);
} else if (!strncmp(dot + 1, "add", (size_t) (eq - dot - 1)) ||
!strncmp(dot + 1, "additivity", (size_t) (eq - dot - 1))) {
char *neweq = xbt_strdup(eq + 1);
} else {
set->additivity = 0;
}
- free(neweq);
+ xbt_free(neweq);
} else if (!strncmp(dot + 1, "app", (size_t) (eq - dot - 1)) ||
!strncmp(dot + 1, "appender", (size_t) (eq - dot - 1))) {
char *neweq = xbt_strdup(eq + 1);
} else {
THROWF(arg_error, 0, "Unknown appender log type: '%s'", neweq);
}
- free(neweq);
+ xbt_free(neweq);
} else if (!strncmp(dot + 1, "fmt", (size_t) (eq - dot - 1))) {
set->fmt = xbt_strdup(eq + 1);
} else {
if (cat->appender) {
if (cat->appender->free_)
cat->appender->free_(cat->appender);
- free(cat->appender);
+ xbt_free(cat->appender);
}
cat->appender = app;
}
if (cat->layout->free_) {
cat->layout->free_(cat->layout);
}
- free(cat->layout);
+ xbt_free(cat->layout);
}
cat->layout = lay;
xbt_log_additivity_set(cat, 0);