Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Logger class #3076

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
58c1228
Use Printf/Fprintf instead of std::cout, std::cerr
Sep 9, 2024
6453b21
Fix formatting
github-actions[bot] Sep 9, 2024
527e85b
Add missing std::endl
alkino Sep 10, 2024
ccbbaf1
Fix formatting
github-actions[bot] Sep 10, 2024
11a651a
Add a missing include
alkino Sep 10, 2024
25308a2
Merge remote-tracking branch 'origin/cornu/no_more_cerr_cout'
alkino Sep 10, 2024
39227a4
Add new missing include
alkino Sep 10, 2024
7e76e65
Modernize printers with fmt
alkino Sep 10, 2024
70f65a7
Fix formatting
github-actions[bot] Sep 10, 2024
c4c2c9a
Sections is now c++
alkino Sep 10, 2024
622cd5d
One missing include
alkino Sep 10, 2024
fad36ce
One missing include
alkino Sep 10, 2024
418a371
Merge remote-tracking branch 'origin/master'
alkino Sep 10, 2024
91d3fb0
Missing header
alkino Sep 10, 2024
c02b4eb
Missing header
alkino Sep 10, 2024
2560d5d
Missing header
alkino Sep 10, 2024
4818eb7
Merge remote-tracking branch 'origin/cornu/no_more_cerr_cout'
alkino Sep 10, 2024
352ce79
Merge remote-tracking branch 'origin/master'
Sep 11, 2024
d9214f3
Don't touch inithoc
Sep 11, 2024
ef6d4ca
Move sections.c to cpp
Sep 11, 2024
62b88a3
Simplify
Sep 11, 2024
b338163
Fix
Sep 11, 2024
ec614d8
Perfect forwarding
Sep 12, 2024
80fc72f
No more static
Sep 12, 2024
083b829
Fix wrong error message args
Sep 12, 2024
28d8ef9
Add a class for Logger
Sep 12, 2024
1b752da
Use the new logger
Sep 12, 2024
04af73f
format
Sep 12, 2024
479920e
Merge remote-tracking branch 'origin/master'
Sep 15, 2024
39dcc35
getCb => getCallback
Sep 15, 2024
58079a0
Merge remote-tracking branch 'origin/master'
Sep 16, 2024
ff32e90
Add the include to be able to format std::array
Sep 16, 2024
af037de
Fix formatting
github-actions[bot] Sep 16, 2024
e48c6dc
Use std::function<> for more portability
Sep 16, 2024
0d4cb1a
Merge remote-tracking branch 'origin/cornu/create_logger_class'
Sep 16, 2024
79d7d19
No need for LoggerCallback type anymore
Sep 16, 2024
76b8ac1
Follow review
Sep 16, 2024
79afacc
Merge remote-tracking branch 'origin/master'
Sep 16, 2024
5e34343
Use const char* for logger message
Sep 16, 2024
be9c98d
No more Fprintf
Sep 16, 2024
f8182ca
More const
Sep 16, 2024
f38fa06
Review
Sep 17, 2024
38d00e8
Printf -> logger.print
Sep 17, 2024
55ac685
Add a missing const
Sep 17, 2024
4e7f13b
Fix formatting
github-actions[bot] Sep 17, 2024
4bbcd6e
Simplify c_str()
Sep 17, 2024
a66f8a5
Escape { and }
Sep 17, 2024
707f8a2
Merge remote-tracking branch 'origin/cornu/create_logger_class'
Sep 17, 2024
91b4935
Fix weird strings
Sep 17, 2024
434ade7
Avoid string literal operator""s
Sep 17, 2024
bfe9e18
Keep bad align
Sep 17, 2024
3163fdb
Add a logger.printf for user inputed fmt string
Sep 17, 2024
e4b2f91
Remove printf
Sep 18, 2024
3eaeb55
Merge branch 'master' into cornu/create_logger_class
alkino Sep 26, 2024
b28abb8
Use a mirror during the down of gnu.org
alkino Oct 1, 2024
1eae776
Fix the problem for ever
alkino Oct 1, 2024
4110370
Merge branch 'master' into cornu/create_logger_class
alkino Oct 1, 2024
37c5464
Don't import fmt if this is already here (spack?)
alkino Oct 1, 2024
515b049
Merge remote-tracking branch 'origin/cornu/create_logger_class'
alkino Oct 1, 2024
6fe9d38
Merge remote-tracking branch 'origin/master'
alkino Oct 1, 2024
e59accd
debug
alkino Oct 1, 2024
96645b2
Try
alkino Oct 1, 2024
50f0e36
more try
alkino Oct 1, 2024
31757d1
Merge remote-tracking branch 'origin/master'
Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/ivoc/ivoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,9 @@ int Oc::run(const char* buf, bool show_err_mes) {
err = hoc_oc(buf);
} catch (std::exception const& e) {
if (show_err_mes) {
Fprintf(stderr, "Oc::run: caught exception");
std::string_view what{e.what()};
if (!what.empty()) {
Fprintf(stderr, fmt::format(": {}", what).c_str());
}
Fprintf(stderr, "\n");
std::string message = what.empty() ? "" : fmt::format(": {}", what);
alkino marked this conversation as resolved.
Show resolved Hide resolved
logger.error("Oc::run: caught exception{}\n", message);
}
err = 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ivoc/strfun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static double l_head(void*) {
result = sm.prefix().str();
}
} catch (const std::regex_error& e) {
Fprintf(stderr, fmt::format("{}\n", e.what()).c_str());
logger.error("{}\n", e.what());
}
char** head = hoc_pgargstr(3);
hoc_assign_str(head, result.c_str());
Expand All @@ -84,7 +84,7 @@ static double l_tail(void*) {
result = sm.suffix().str();
}
} catch (const std::regex_error& e) {
Fprintf(stderr, fmt::format("{}\n", e.what()).c_str());
logger.error("{}\n", e.what());
}
char** tail = hoc_pgargstr(3);
hoc_assign_str(tail, result.c_str());
Expand Down
14 changes: 6 additions & 8 deletions src/neuron/container/soa_identifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,12 @@ struct owning_identifier {
// auto const read_only_token = node_data.issue_frozen_token();
// list_of_nodes.pop_back();
// which tries to delete a row from a container in read-only mode.
Fprintf(stderr,
fmt::format(
"neuron::container::owning_identifier<{}> destructor could not delete from "
"the underlying storage: {} [{}]. This is not recoverable, aborting.\n",
cxx_demangle(typeid(Storage).name()),
e.what(),
cxx_demangle(typeid(e).name()))
.c_str());
logger.error(
"neuron::container::owning_identifier<{}> destructor could not delete from "
"the underlying storage: {} [{}]. This is not recoverable, aborting.\n",
cxx_demangle(typeid(Storage).name()),
e.what(),
cxx_demangle(typeid(e).name()));
terminate = true;
}
if (terminate) {
Expand Down
6 changes: 3 additions & 3 deletions src/neuronmusic/nrnmusic_dynam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ static void load_music() {
// every rank if nhost is large. So demand ...
const_char_ptr music_path = const_char_ptr{std::getenv("NRN_LIBMUSIC_PATH")};
if (!music_path) {
Fprintf(stderr, "No NRN_LIBMUSIC_PATH environment variable for full path to libmusic\n");
logger.error("No NRN_LIBMUSIC_PATH environment variable for full path to libmusic\n");
exit(1);
}
handle = dlopen(music_path, RTLD_NOW | RTLD_GLOBAL);
if (!handle) {
Fprintf(stderr, "%s", dlerror());
logger.error(dlerror());
exit(1);
}
}
Expand Down Expand Up @@ -67,7 +67,7 @@ void nrnmusic_load() {

void* handle = dlopen(nrnmusic_library.c_str(), RTLD_NOW | RTLD_GLOBAL);
if (!handle) {
Fprintf(stderr, "%s\n", dlerror());
logger.error("{}\n", dlerror());
exit(1);
}
assert(handle);
Expand Down
7 changes: 3 additions & 4 deletions src/nrncvode/netcvode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5578,10 +5578,9 @@ static int trajec_buffered(NrnThread& nt,
} else {
err = nrn_dblpntr2nrncore(pd, nt, types[i_trajec], indices[i_trajec]);
if (err) {
Fprintf(stderr,
"Pointer %p of PlayRecord type %d ignored because not a Range Variable",
fmt::ptr(static_cast<double*>(pd)),
pr->type());
logger.error("Pointer {} of PlayRecord type {} ignored because not a Range Variable",
fmt::ptr(static_cast<double*>(pd)),
pr->type());
}
}
return err;
Expand Down
12 changes: 6 additions & 6 deletions src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,12 +1015,12 @@ static void set_info(TQItem* tqi,
core_te->type.pop_back();
// Delivery time was often reduced by a quarter step to avoid
// fixed step roundoff problems.
Fprintf(stderr,
"WARNING: CVode.event(...) for delivery at time step nearest %g discarded. "
"CoreNEURON cannot presently handle interpreter events (rank %d, thread %d).\n",
tdeliver,
nrnmpi_myid,
tid);
logger.error(
"WARNING: CVode.event(...) for delivery at time step nearest {} discarded. "
"CoreNEURON cannot presently handle interpreter events (rank {}, thread {}).\n",
tdeliver,
nrnmpi_myid,
tid);
} break;
case PlayRecordEventType: { // 6
} break;
Expand Down
45 changes: 17 additions & 28 deletions src/nrniv/nrnpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <cctype>
#include <sstream>

#include <fmt/ranges.h> // for the formatter of std::array

namespace neuron::python {
// Declared extern in nrnpy.h, defined here.
impl_ptrs methods;
Expand Down Expand Up @@ -217,15 +219,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
Expand Down Expand Up @@ -263,12 +262,9 @@ 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;
Expand All @@ -279,18 +275,13 @@ 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 "
"NRN_PYLIB, NRN_PYTHONEXE and NRN_PYTHONVERSION settings that are "
"incompatible with this NEURON. Try unsetting them.\n");
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",
pyversion,
supported_versions);
return nullptr;
}
}
Expand All @@ -306,15 +297,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<nrnpython_reg_real_t>(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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/nrnmpi/nrnmpi_dynam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ std::string nrnmpi_load() {
return true;
};
if (!promote_to_global("libnrniv.so") && !promote_to_global("libnrniv-without-nvidia.so")) {
Fprintf(stderr, fmt::format("{} to RTLD_GLOBAL\n", error).c_str());
logger.error("{} to RTLD_GLOBAL\n", error);
}
}
#endif
Expand Down
7 changes: 3 additions & 4 deletions src/nrnoc/cabcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,9 @@ Prop* nrn_mechanism_check(int type, Section* sec, int inode) {
m = nrn_mechanism(type, sec->pnode[inode]);
if (!m) {
if (hoc_execerror_messages) {
Fprintf(stderr,
"%s mechanism not inserted in section %s\n",
memb_func[type].sym->name,
secname(sec));
logger.error("{} mechanism not inserted in section {}\n",
memb_func[type].sym->name,
secname(sec));
}
hoc_execerror("", (char*) 0);
}
Expand Down
6 changes: 3 additions & 3 deletions src/nrnoc/eion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ void nrn_verify_ion_charge_defined() {
if (nrn_is_ion(i)) {
if (global_charge(i) == VAL_SENTINAL) {
Symbol* s = memb_func[i].sym;
Fprintf(stderr,
"%s USEION CHARGE (or VALENCE) must be defined in\n\
logger.error(
"{} USEION CHARGE (or VALENCE) must be defined in\n\
at least one model using this ion\n",
s->name);
s->name);
nrn_exit(1);
}
}
Expand Down
34 changes: 16 additions & 18 deletions src/nrnoc/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,9 @@ void* nrn_realpath_dlopen(const char* relpath, int flags) {
} catch (const std::filesystem::filesystem_error& e) {
handle = dlopen(relpath, flags);
if (!handle) {
Fprintf(
stderr,
fmt::format("std::filesystem::absolute failed ({}) and dlopen failed with '{}'\n",
e.what(),
relpath)
.c_str());
logger.error("std::filesystem::absolute failed ({}) and dlopen failed with '{}'\n",
e.what(),
relpath);
#if DARWIN
nrn_possible_mismatched_arch(relpath);
#endif
Expand Down Expand Up @@ -312,12 +309,13 @@ void hoc_last_init(void) {
hoc_register_var(scdoub, (DoubVec*) 0, (VoidFunc*) 0);
nrn_threads_create(1, false); // single thread

if (nrnmpi_myid < 1)
if (nrnmpi_myid < 1) {
if (nrn_nobanner_ == 0) {
Fprintf(stderr, "%s\n", nrn_version(1));
Fprintf(stderr, "%s\n", banner);
logger.error("{}\n", nrn_version(1));
logger.error("{}\n", banner);
IGNORE(fflush(stderr));
}
}
memb_func_size_ = 30; // initial allocation size
memb_list.reserve(memb_func_size_);
memb_func.resize(memb_func_size_); // we directly resize because it is used below
Expand Down Expand Up @@ -700,21 +698,21 @@ void check_mech_version(const char** m) {
/*printf("%s %s\n", m[0], m[1]);*/
if (strcmp(m[0], "0") == 0) { /* valid by nature */
} else if (m[0][0] > '9') { /* must be 5.1 or before */
Fprintf(stderr,
"Mechanism %s needs to be re-translated.\n\
It's pre version 6.0 \"c\" code is incompatible with this neuron version.\n",
m[0]);
logger.error(
"Mechanism {} needs to be re-translated.\n"
"It's pre version 6.0 \"c\" code is incompatible with this neuron version.\n",
m[0]);
if (nrn_load_dll_recover_error()) {
hoc_execerror("Mechanism needs to be retranslated:", m[0]);
} else {
nrn_exit(1);
}
} else if (strcmp(m[0], nmodl_version_) != 0) {
Fprintf(stderr,
"Mechanism %s needs to be re-translated.\n\
It's version %s \"c\" code is incompatible with this neuron version.\n",
m[1],
m[0]);
logger.error(
"Mechanism {} needs to be re-translated.\n"
"It's version {} \"c\" code is incompatible with this neuron version.\n",
m[1],
m[0]);
if (nrn_load_dll_recover_error()) {
hoc_execerror("Mechanism needs to be retranslated:", m[1]);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/nrnoc/solve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void nrn_solve(NrnThread* _nt) {
nrn_thread_error("debugsolve");
err = debugsolve();
if (err > 1.e-10) {
Fprintf(stderr, "solve error = %g\n", err);
logger.error("solve error = {}\n", err);
}
}
#else
Expand Down
Loading
Loading