diff --git a/src/nrniv/nrnpy.cpp b/src/nrniv/nrnpy.cpp index be8b723df4..ac3fa51eb2 100644 --- a/src/nrniv/nrnpy.cpp +++ b/src/nrniv/nrnpy.cpp @@ -217,15 +217,12 @@ void nrnpython_reg() { try { set_nrnpylib(); } catch (std::exception const& e) { - Fprintf(stderr, - fmt::format("Could not determine Python library details: {}\n", e.what()) - .c_str()); + logger().error("Could not determine Python library details: {}\n", e.what()); exit(1); } handle = dlopen(nrnpy_pylib.c_str(), RTLD_NOW | RTLD_GLOBAL); if (!handle) { - Fprintf(stderr, - fmt::format("Could not dlopen NRN_PYLIB: {}\n", nrnpy_pylib).c_str()); + logger().error("Could not dlopen NRN_PYLIB: {}\n", nrnpy_pylib); #if DARWIN nrn_possible_mismatched_arch(nrnpy_pylib.c_str()); #endif @@ -263,12 +260,7 @@ static nrnpython_reg_real_t load_nrnpython() { pyversion = std::to_string(pv10 / factor) + "." + std::to_string(pv10 % factor); } else { if (nrnpy_pylib.empty() || nrnpy_pyversion.empty()) { - Fprintf( - stderr, - fmt::format("Do not know what Python to load [nrnpy_pylib={} nrnpy_pyversion={}]\n", - nrnpy_pylib, - nrnpy_pyversion) - .c_str()); + logger().error("Do not know what Python to load [nrnpy_pylib={} nrnpy_pyversion={}]\n", nrnpy_pylib, nrnpy_pyversion); return nullptr; } pyversion = nrnpy_pyversion; @@ -279,18 +271,10 @@ static nrnpython_reg_real_t load_nrnpython() { auto const iter = std::find(supported_versions.begin(), supported_versions.end(), pyversion); if (iter == supported_versions.end()) { - Fprintf( - stderr, - fmt::format("Python {} is not supported by this NEURON installation (supported:", - pyversion) - .c_str()); - for (auto const& good_ver: supported_versions) { - Fprintf(stderr, fmt::format(" {}", good_ver).c_str()); - } - Fprintf(stderr, - "). If you are seeing this message, your environment probably contains " + logger().error("Python {} is not supported by this NEURON installation (supported: {})." + "If you are seeing this message, your environment probably contains " "NRN_PYLIB, NRN_PYTHONEXE and NRN_PYTHONVERSION settings that are " - "incompatible with this NEURON. Try unsetting them.\n"); + "incompatible with this NEURON. Try unsetting them.\n", pyversion, fmt::join(supported_versions, " ")); return nullptr; } } @@ -306,15 +290,13 @@ static nrnpython_reg_real_t load_nrnpython() { #endif auto* const handle = dlopen(name.c_str(), RTLD_NOW); if (!handle) { - Fprintf(stderr, fmt::format("Could not load {}\n", name).c_str()); - Fprintf(stderr, - fmt::format("nrn_is_python_extension={}\n", nrn_is_python_extension).c_str()); + logger().error("Could not load {}\n", name); + logger().error("nrn_is_python_extension={}\n", nrn_is_python_extension); return nullptr; } auto* const reg = reinterpret_cast(dlsym(handle, "nrnpython_reg_real")); if (!reg) { - Fprintf(stderr, - fmt::format("Could not load registration function from {}\n", name).c_str()); + logger().error("Could not load registration function from {}\n", name); } return reg; } diff --git a/src/oc/fileio.cpp b/src/oc/fileio.cpp index 6ab983a3ed..3f44f0509f 100644 --- a/src/oc/fileio.cpp +++ b/src/oc/fileio.cpp @@ -34,7 +34,7 @@ void nrnpy_pass() { } extern "C" void nrnpy_set_pr_etal(LoggerCallback* cb, int(*cbpass)(void)) { - getLogger().setCallback(cb); + logger().setCallback(cb); nrnpy_pass_callback = cbpass; } diff --git a/src/utils/logger.hpp b/src/utils/logger.hpp index 2c6f981ee6..4c0f71a432 100644 --- a/src/utils/logger.hpp +++ b/src/utils/logger.hpp @@ -38,17 +38,17 @@ class Logger { LoggerCallback* callback = nullptr; }; -extern Logger nrnpy_logger; +extern Logger nrn_logger; -inline Logger& getLogger() { - return nrnpy_logger; +inline Logger& logger() { + return nrn_logger; } template int Fprintf(FILE* stream, const char* fmt, T... args) { - if (getLogger().getCallback() && (stream == stdout || stream == stderr)) { + if (logger().getCallback() && (stream == stdout || stream == stderr)) { std::string message = fmt::sprintf(fmt, args...); - getLogger().getCallback()(stream == stdout ? 1 : 2, message.c_str()); + logger().getCallback()(stream == stdout ? 1 : 2, message.c_str()); return message.size(); } return fmt::fprintf(stream, fmt, args...); @@ -56,9 +56,9 @@ int Fprintf(FILE* stream, const char* fmt, T... args) { template int Printf(const char* fmt, T... args) { - if (getLogger().getCallback()) { + if (logger().getCallback()) { std::string message = fmt::sprintf(fmt, args...); - getLogger().getCallback()(1, message.c_str()); + logger().getCallback()(1, message.c_str()); return message.size(); } return fmt::printf(fmt, args...);