/* 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 <ctype.h>
+#include <algorithm>
+#include <cctype>
+#include <cstdarg>
+#include <cstdio> /* snprintf */
+#include <cstdlib>
#include <mutex>
-#include <stdarg.h>
-#include <stdio.h> /* snprintf */
-#include <stdlib.h> /* snprintf */
#include "src/internal_config.h"
#include "xbt/str.h"
#include "xbt/sysdep.h"
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
-
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;
* For more information, please refer to @ref outcomes_logs Section.
*/
-xbt_log_appender_t xbt_log_default_appender = NULL; /* set in log_init */
-xbt_log_layout_t xbt_log_default_layout = NULL; /* set in log_init */
+xbt_log_appender_t xbt_log_default_appender = nullptr; /* set in log_init */
+xbt_log_layout_t xbt_log_default_layout = nullptr; /* set in log_init */
typedef struct {
char *catname;
typedef s_xbt_log_setting_t* xbt_log_setting_t;
-static xbt_dynar_t xbt_log_settings = NULL;
+static xbt_dynar_t xbt_log_settings = nullptr;
static void _free_setting(void *s)
{
};
s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT) = {
- NULL /*parent */ , NULL /* firstChild */ , NULL /* nextSibling */ ,
- "root", "The common ancestor for all categories",
- 0 /*initialized */, xbt_log_priority_uninitialized /* threshold */ ,
- 0 /* isThreshInherited */ ,
- NULL /* appender */ , NULL /* layout */ ,
- 0 /* additivity */
+ nullptr /*parent */,
+ nullptr /* firstChild */,
+ nullptr /* nextSibling */,
+ "root",
+ "The common ancestor for all categories",
+ 0 /*initialized */,
+ xbt_log_priority_uninitialized /* threshold */,
+ 0 /* isThreshInherited */,
+ nullptr /* appender */,
+ nullptr /* layout */,
+ 0 /* additivity */
};
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log, xbt, "Loggings from the logging mechanism itself");
which were already created (damnit. Too slow little beetle) */
void xbt_log_preinit(void)
{
- xbt_log_default_appender = xbt_log_appender_file_new(NULL);
- xbt_log_default_layout = xbt_log_layout_simple_new(NULL);
+ xbt_log_default_appender = xbt_log_appender_file_new(nullptr);
+ xbt_log_default_layout = xbt_log_layout_simple_new(nullptr);
_XBT_LOGV(XBT_LOG_ROOT_CAT).appender = xbt_log_default_appender;
_XBT_LOGV(XBT_LOG_ROOT_CAT).layout = xbt_log_default_layout;
log_cat_init_mutex = new std::recursive_mutex();
}
}
if (j < *argc) {
- argv[j] = NULL;
+ argv[j] = nullptr;
*argc = j;
}
free(cat->layout);
}
- for (child = cat->firstChild; child != NULL; child = child->nextSibling)
+ for (child = cat->firstChild; child != nullptr; child = child->nextSibling)
log_cat_exit(child);
}
}
/* Size of the static string in which we build the log string */
-#define XBT_LOG_STATIC_BUFFER_SIZE 2048
+static constexpr size_t XBT_LOG_STATIC_BUFFER_SIZE = 2048;
/* Minimum size of the dynamic string in which we build the log string
(should be greater than XBT_LOG_STATIC_BUFFER_SIZE) */
-#define XBT_LOG_DYNAMIC_BUFFER_SIZE 4096
+static constexpr size_t XBT_LOG_DYNAMIC_BUFFER_SIZE = 4096;
void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...)
{
while (1) {
xbt_log_appender_t appender = cat->appender;
- if (appender != NULL) {
+ if (appender != nullptr) {
xbt_assert(cat->layout, "No valid layout for the appender of category %s", cat->name);
/* First, try with a static buffer */
* To circumvent the problem, we define the macro DISABLE_XBT_LOG_CAT_INIT() to hide the real _xbt_log_cat_init(). The
* macro has to be called at the beginning of the affected functions.
*/
-static int fake_xbt_log_cat_init(xbt_log_category_t XBT_ATTRIB_UNUSED category,
- e_xbt_log_priority_t XBT_ATTRIB_UNUSED priority)
+static int fake_xbt_log_cat_init(xbt_log_category_t, e_xbt_log_priority_t)
{
return 0;
}
if (setting->appender) {
xbt_log_appender_set(category, setting->appender);
if (!category->layout)
- xbt_log_layout_set(category, xbt_log_layout_simple_new(NULL));
+ xbt_log_layout_set(category, xbt_log_layout_simple_new(nullptr));
category->additivity = 0;
XBT_DEBUG("Set %p as appender of category '%s'", setting->appender, category->name);
}
int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority)
{
DISABLE_XBT_LOG_CAT_INIT();
- if (log_cat_init_mutex != NULL)
+ if (log_cat_init_mutex != nullptr)
log_cat_init_mutex->lock();
if (category->initialized) {
- if (log_cat_init_mutex != NULL)
+ if (log_cat_init_mutex != nullptr)
log_cat_init_mutex->unlock();
return priority >= category->threshold;
}
unsigned int cursor;
- xbt_log_setting_t setting = NULL;
+ xbt_log_setting_t setting = nullptr;
XBT_DEBUG("Initializing category '%s' (firstChild=%s, nextSibling=%s)", category->name,
(category->firstChild ? category->firstChild->name : "none"),
if (XBT_LOG_ISENABLED(log, xbt_log_priority_debug)) {
char *buf;
- char *res = NULL;
+ char* res = nullptr;
xbt_log_category_t cpp = category->parent->firstChild;
while (cpp) {
if (res) {
}
category->initialized = 1;
- if (log_cat_init_mutex != NULL)
+ if (log_cat_init_mutex != nullptr)
log_cat_init_mutex->unlock();
return priority >= category->threshold;
}
if (cat->initialized) {
xbt_log_category_t *cpp = &cat->parent->firstChild;
- while (*cpp != cat && *cpp != NULL) {
+ while (*cpp != cat && *cpp != nullptr) {
cpp = &(*cpp)->nextSibling;
}
{
xbt_log_category_t child = cat->firstChild;
- for (; child != NULL; child = child->nextSibling) {
+ for (; child != nullptr; child = child->nextSibling) {
if (child->isThreshInherited) {
if (cat != &_XBT_LOGV(log))
XBT_VERB("Set category threshold of %s to %s (=%d)",
const char *orig_control_string = control_string;
xbt_log_setting_t set = xbt_new(s_xbt_log_setting_t, 1);
- set->catname = NULL;
+ set->catname = nullptr;
set->thresh = xbt_log_priority_uninitialized;
- set->fmt = NULL;
+ set->fmt = nullptr;
set->additivity = -1;
- set->appender = NULL;
+ set->appender = nullptr;
if (!*control_string)
return set;
set->fmt = xbt_strdup(eq + 1);
} else {
char buff[512];
- snprintf(buff, MIN(512, eq - dot), "%s", dot + 1);
+ snprintf(buff, std::min<int>(512, eq - dot), "%s", dot + 1);
xbt_die("Unknown setting of the log category: '%s'", buff);
}
set->catname = (char *) xbt_malloc(dot - name + 1);
if (!strcmp(cat->name, name))
return cat;
- for (child = cat->firstChild; child != NULL; child = child->nextSibling) {
+ for (child = cat->firstChild; child != nullptr; child = child->nextSibling) {
XBT_DEBUG("Dig into %s", child->name);
res = _xbt_log_cat_searchsub(child, name);
if (res)
return res;
}
- return NULL;
+ return nullptr;
}
/**
return;
}
/* some initialization if this is the first time that this get called */
- if (xbt_log_settings == NULL)
+ if (xbt_log_settings == nullptr)
xbt_log_settings = xbt_dynar_new(sizeof(xbt_log_setting_t), _free_setting);
/* split the string, and remove empty entries */
DISABLE_XBT_LOG_CAT_INIT();
if (!cat->appender) {
XBT_VERB ("No appender to category %s. Setting the file appender as default", cat->name);
- xbt_log_appender_set(cat, xbt_log_appender_file_new(NULL));
+ xbt_log_appender_set(cat, xbt_log_appender_file_new(nullptr));
}
if (cat->layout) {
if (cat->layout->free_) {
child_prefix = xbt_strdup(prefix);
}
- xbt_dynar_t dynar = xbt_dynar_new(sizeof(xbt_log_category_t), NULL);
- for (cat = category ; cat != NULL; cat = cat->nextSibling)
+ xbt_dynar_t dynar = xbt_dynar_new(sizeof(xbt_log_category_t), nullptr);
+ for (cat = category; cat != nullptr; cat = cat->nextSibling)
xbt_dynar_push_as(dynar, xbt_log_category_t, cat);
xbt_dynar_sort(dynar, xbt_log_cat_cmp);
#include "src/internal_config.h"
#include "src/xbt/log_private.hpp"
#include "xbt/sysdep.h"
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
static void append_file(xbt_log_appender_t this_, char *str) {
fputs(str, (FILE *) this_->data);
res->free_ = &free_;
if (arg) {
res->data = (void *) fopen(arg, "w");
- if (res->data == NULL)
+ if (res->data == nullptr)
xbt_die("Cannot open file: %s: %s", arg, strerror(errno));
} else {
res->data = (void *) stderr;
};
typedef struct xbt_log_append2_file_s* xbt_log_append2_file_t;
-#define APPEND2_END_TOKEN "\n[End of log]\n"
-#define APPEND2_END_TOKEN_CLEAR "\n "
+static constexpr const char* APPEND2_END_TOKEN = "\n[End of log]\n";
+static constexpr const char* APPEND2_END_TOKEN_CLEAR = "\n ";
static void open_append2_file(xbt_log_append2_file_t data){
if(data->count<0) {
//Roll
if (!data->file) {
data->file= fopen(data->filename, "w");
- if (data->file == NULL)
+ if (data->file == nullptr)
xbt_die("Cannot open file: %s: %s", data->filename, strerror(errno));
} else {
fputs(APPEND2_END_TOKEN_CLEAR,data->file);
snprintf(newname,511,"%s%i%s",pre,data->count,post);
data->count++;
data->file= fopen(newname, "w");
- if (data->file == NULL)
+ if (data->file == nullptr)
xbt_die("Cannot open file: %s: %s", newname, strerror(errno));
xbt_free(pre);
}
xbt_assert(arg);
char* buf=xbt_strdup(arg);
char* sep=strchr(buf,':');
- xbt_assert(sep != NULL);
+ xbt_assert(sep != nullptr);
data->filename=xbt_strdup(sep+1);
*sep='\0';
char *endptr;
#include "simgrid/msg.h" /* MSG_get_clock */
#include "src/xbt/log_private.hpp"
#include "xbt/sysdep.h"
-#include <stdio.h>
-
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
+#include <algorithm>
+#include <cstdio>
extern const char *xbt_log_priority_names[8];
-#define ERRMSG \
- "Unknown %%%c sequence in layout format (%s).\n" \
- "Known sequences:\n" \
- " what: %%m: user message %%c: log category %%p: log priority\n" \
- " where:\n" \
- " source: %%F: file %%L: line %%M: function %%l: location (%%F:%%L)\n" \
- " runtime: %%h: hostname %%t: thread %%P: process %%i: PID\n" \
- " when: %%d: date %%r: app. age\n" \
- " other: %%%%: %% %%n: new line %%e: plain space\n"
+static constexpr const char* ERRMSG =
+ "Unknown %%%c sequence in layout format (%s).\n"
+ "Known sequences:\n"
+ " what: %%m: user message %%c: log category %%p: log priority\n"
+ " where:\n"
+ " source: %%F: file %%L: line %%M: function %%l: location (%%F:%%L)\n"
+ " runtime: %%h: hostname %%t: thread %%P: process %%i: PID\n"
+ " when: %%d: date %%r: app. age\n"
+ " other: %%%%: %% %%n: new line %%e: plain space\n";
#define check_overflow(len) \
if ((rem_size -= (len)) > 0) { \
#define show_int(data) show_it(data, "d")
#define show_double(data) show_it(data, "f")
-static int xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_log_event_t ev, const char *msg_fmt)
+static int xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_log_event_t ev, const char* msg_fmt)
{
char *p = ev->buffer;
int rem_size = ev->buffer_size;
int sz;
set_sz_from_precision();
int len = snprintf(p, sz, "%s:%d", ev->fileName, ev->lineNum);
- check_overflow(MIN(sz, len));
+ check_overflow(std::min(sz, len));
break;
}
case 'L': /* line number; LOG4J compliant */
va_copy(ap, ev->ap);
int len = vsnprintf(p, sz, msg_fmt, ap);
va_end(ap);
- check_overflow(MIN(sz, len));
+ check_overflow(std::min(sz, len));
break;
}
default: