X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/539af86e870c62ba4a28b5b4e0cedd252881dfb0..e3edcce3fad8dab51ab79373c6ef6c7e88990973:/src/xbt/log.cpp diff --git a/src/xbt/log.cpp b/src/xbt/log.cpp index e4525c36ab..8113f3691d 100644 --- a/src/xbt/log.cpp +++ b/src/xbt/log.cpp @@ -1,6 +1,6 @@ /* log - a generic logging facility in the spirit of log4j */ -/* Copyright (c) 2004-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -37,9 +37,14 @@ struct xbt_log_setting_t { xbt_log_appender_t appender = nullptr; }; -static std::vector xbt_log_settings; +// This function is here to avoid static initialization order fiasco +static auto& xbt_log_settings() +{ + static std::vector value; + return value; +} -const std::array xbt_log_priority_names{ +constexpr std::array xbt_log_priority_names{ {"NONE", "TRACE", "DEBUG", "VERBOSE", "INFO", "WARNING", "ERROR", "CRITICAL"}}; s_xbt_log_category_t _XBT_LOGV(XBT_LOG_ROOT_CAT) = { @@ -161,7 +166,7 @@ void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...) xbt_assert(cat->layout, "No valid layout for the appender of category %s", cat->name); /* First, try with a static buffer */ - int done = 0; + bool done = false; std::array buff; ev->buffer = buff.data(); ev->buffer_size = buff.size(); @@ -286,11 +291,11 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority } /* Apply the control */ - auto iset = std::find_if(begin(xbt_log_settings), end(xbt_log_settings), + auto iset = std::find_if(begin(xbt_log_settings()), end(xbt_log_settings()), [category](const xbt_log_setting_t& s) { return s.catname == category->name; }); - if (iset != xbt_log_settings.end()) { + if (iset != xbt_log_settings().end()) { _xbt_log_cat_apply_set(category, *iset); - xbt_log_settings.erase(iset); + xbt_log_settings().erase(iset); } else { XBT_DEBUG("Category '%s': inherited threshold = %s (=%d)", category->name, xbt_log_priority_names[category->threshold], category->threshold); @@ -500,7 +505,7 @@ void xbt_log_control_set(const char *control_string) } else { XBT_DEBUG("Store for further application"); XBT_DEBUG("push %p to the settings", &set); - xbt_log_settings.emplace_back(std::move(set)); + xbt_log_settings().emplace_back(std::move(set)); } } xbt_dynar_free(&set_strings); @@ -567,7 +572,7 @@ static void xbt_log_help() " -> %%p: Priority name (LOG4J compatible)\n" "\n" " -> %%h: Hostname (SimGrid extension)\n" - " -> %%P: Process name (SimGrid extension)\n" + " -> %%a: Actor name (SimGrid extension)\n" " -> %%t: Thread \"name\" (LOG4J compatible -- actually the address of the thread in memory)\n" " -> %%i: Process PID (SimGrid extension -- this is a 'i' as in 'i'dea)\n" "\n"