diff --git a/CMakeLists.txt b/CMakeLists.txt index 87d423a7b4..8c7c29c8bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,8 +246,14 @@ endif() include("${CODING_CONV_CMAKE}/3rdparty.cmake") cpp_cc_git_submodule(Random123) cpp_cc_git_submodule(eigen) -nrn_add_external_project(fmt) -set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON) +find_package(fmt) +if(NOT fmt_FOUND) + message(STATUS "importing fmt from submodule") + nrn_add_external_project(fmt) + set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON) +else() + message(STATUS "fmt has been found on the system") +endif() file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/external/Random123/include/Random123" DESTINATION "${CMAKE_BINARY_DIR}/include/") diff --git a/src/ivoc/ivoc.cpp b/src/ivoc/ivoc.cpp index 790401759d..3bdea23c3e 100644 --- a/src/ivoc/ivoc.cpp +++ b/src/ivoc/ivoc.cpp @@ -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() ? std::string("") : fmt::format(": {}", what); + logger.error("Oc::run: caught exception{}\n", message); } err = 1; } diff --git a/src/ivoc/ivocmain.cpp b/src/ivoc/ivocmain.cpp index 226b37cf11..f7941024cc 100644 --- a/src/ivoc/ivocmain.cpp +++ b/src/ivoc/ivocmain.cpp @@ -314,7 +314,7 @@ void hoc_nrnmpi_init() { nrnmpi_stubs(); auto const pmes = nrnmpi_load(); if (!pmes.empty()) { - Printf(fmt::format("{}\n", pmes).c_str()); + logger.print("{}\n", pmes); } #endif diff --git a/src/ivoc/ivocvect.cpp b/src/ivoc/ivocvect.cpp index 9681a6b270..5079f26f46 100644 --- a/src/ivoc/ivocvect.cpp +++ b/src/ivoc/ivocvect.cpp @@ -37,6 +37,7 @@ #include "gui-redirect.h" #include "utils/logger.hpp" +#include #ifndef PI #ifndef M_PI @@ -787,13 +788,13 @@ static double v_printf(void* v) { fprintf(f->file(), "\n"); } else { for (int i = start; i <= end; i++) { - Printf(format, x->elem(i)); + logger.print(fmt::sprintf(format, x->elem(i))); if (extra_newline && !((i - start + 1) % 5)) { - Printf("\n"); + logger.print("\n"); } } if (extra_newline) { - Printf("\n"); + logger.print("\n"); } } hoc_return_type_code = 1; // integer @@ -2582,7 +2583,7 @@ static double simplex(double* p, int n, Vect* x, Vect* y, char* fcn) { nvortex = (double*) calloc(n * 4, (unsigned) sizeof(double)); if (0 == evortex || 0 == gvortex || 0 == vortex || 0 == nvortex) { - Printf("allocation error in simplex()\n"); + logger.print("allocation error in simplex()\n"); nrn_exit(1); } diff --git a/src/ivoc/matrix.cpp b/src/ivoc/matrix.cpp index 8fa098d61d..d4b1072389 100644 --- a/src/ivoc/matrix.cpp +++ b/src/ivoc/matrix.cpp @@ -9,6 +9,7 @@ #include "ivocvect.h" #include "utils/logger.hpp" +#include #define EPS hoc_epsilon Symbol* nrn_matrix_sym; // also used in oc/hoc_oop.cpp @@ -116,9 +117,9 @@ static double m_printf(void* v) { } for (i = 0; i < nrow; ++i) { for (j = 0; j < ncol; ++j) { - Printf(f1, m->getval(i, j)); + logger.print(fmt::sprintf(f1, m->getval(i, j))); } - Printf("%s", f2); + logger.print("{}", f2); } return 0.; } diff --git a/src/ivoc/strfun.cpp b/src/ivoc/strfun.cpp index 721dae09ec..f019d1c886 100644 --- a/src/ivoc/strfun.cpp +++ b/src/ivoc/strfun.cpp @@ -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()); @@ -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()); @@ -238,9 +238,9 @@ static int l_ref2(Object* o, Object* ob, int nr) { Object** obp = o->u.dataspace[s->u.oboff].pobj + i; if (*obp == ob) { if (total == 1) { - Printf(" %s.%s\n", hoc_object_name(o), s->name); + logger.print(" {}.{}\n", hoc_object_name(o), s->name); } else { - Printf(" %s.%s[%d]\n", hoc_object_name(o), s->name, i); + logger.print(" {}.{}[{}]\n", hoc_object_name(o), s->name, i); } ++nr; } @@ -262,9 +262,9 @@ static int l_ref1(Symlist* sl, Objectdata* data, Object* ob, int nr) { Object** obp = data[s->u.oboff].pobj + i; if (*obp == ob) { if (total == 1) { - Printf(" %s\n", s->name); + logger.print(" {}\n", s->name); } else { - Printf(" %s[%d]\n", s->name, i); + logger.print(" {}[{}]\n", s->name, i); } ++nr; } @@ -295,7 +295,7 @@ static int l_ref3(Symbol* s, Object* ob, int nr) { ITERATE(q, s->u.ctemplate->olist) { OcBox* b = (OcBox*) (OBJ(q)->u.this_pointer); if (b->keep_ref() == ob) { - Printf(" %s.ref\n", hoc_object_name(OBJ(q))); + logger.print(" {}.ref\n", hoc_object_name(OBJ(q))); ++nr; } } @@ -313,7 +313,7 @@ static int l_ref4(Symbol* s, Object* ob, int nr) { if (list->refs_items()) for (i = 0; i < list->count(); ++i) { if (list->object(i) == ob) { - Printf(" %s.object(%ld)\n", hoc_object_name(OBJ(q)), i); + logger.print(" {}.object({})\n", hoc_object_name(OBJ(q)), i); ++nr; } } @@ -324,7 +324,7 @@ static int l_ref4(Symbol* s, Object* ob, int nr) { static double l_ref(void*) { Object* ob = *hoc_objgetarg(1); int nr = ob ? ob->refcount : 0; - Printf("%s has %d references\n", hoc_object_name(ob), nr); + logger.print("{} has {} references\n", hoc_object_name(ob), nr); hoc_return_type_code = 1; // integer if (nr == 0) { return 0.; @@ -337,7 +337,7 @@ static double l_ref(void*) { nr = l_ref3(hoc_table_lookup("VBox", hoc_built_in_symlist), ob, nr); nr = l_ref4(hoc_table_lookup("List", hoc_built_in_symlist), ob, nr); - Printf(" found %d of them\n", nr); + logger.print(" found {} of them\n", nr); return (double) nr; } diff --git a/src/neuron/container/soa_identifier.hpp b/src/neuron/container/soa_identifier.hpp index 6b8ed98d42..d466af0e26 100644 --- a/src/neuron/container/soa_identifier.hpp +++ b/src/neuron/container/soa_identifier.hpp @@ -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) { diff --git a/src/neuronmusic/nrnmusic_dynam.cpp b/src/neuronmusic/nrnmusic_dynam.cpp index 54039d66c6..2ca4a08e64 100644 --- a/src/neuronmusic/nrnmusic_dynam.cpp +++ b/src/neuronmusic/nrnmusic_dynam.cpp @@ -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); } } @@ -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); diff --git a/src/nrncvode/cvodeobj.cpp b/src/nrncvode/cvodeobj.cpp index d7fc1660ed..33b56d1702 100644 --- a/src/nrncvode/cvodeobj.cpp +++ b/src/nrncvode/cvodeobj.cpp @@ -771,8 +771,8 @@ bool Cvode::at_time(double te, NrnThread* nt) { // beyond the current step. if (nt->_vcv) { if (te <= tstop_ && te > t0_) { - Printf("te=%g t0_=%g tn_=%g t_=%g t=%g\n", te, t0_, tn_, t_, nt_t); - Printf("te-t0_=%g tstop_-te=%g\n", te - t0_, tstop_ - te); + logger.print("te={} t0_={} tn_={} t_={} t={}\n", te, t0_, tn_, t_, nt_t); + logger.print("te-t0_={} tstop_-te={}\n", te - t0_, tstop_ - te); } assert(te > tstop_ || te <= t0_); } @@ -1065,10 +1065,10 @@ int Cvode::cvode_init(double) { err = CVodeReInit(mem_, pf_, t0_, y_, CV_SV, &ncv_->rtol_, atolnvec_); // printf("CVodeReInit\n"); if (err != SUCCESS) { - Printf("Cvode %p %s CVReInit error %d\n", - fmt::ptr(this), - secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), - err); + logger.print("Cvode {} {} CVReInit error {}\n", + fmt::ptr(this), + secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), + err); return err; } } else { @@ -1081,10 +1081,10 @@ int Cvode::cvode_init(double) { maxstep(ncv_->maxstep()); CVodeMalloc(mem_, pf_, t0_, y_, CV_SV, &ncv_->rtol_, atolnvec_); if (err != SUCCESS) { - Printf("Cvode %p %s CVodeMalloc error %d\n", - fmt::ptr(this), - secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), - err); + logger.print("Cvode {} {} CVodeMalloc error {}\n", + fmt::ptr(this), + secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), + err); return err; } // CVodeSetInitStep(mem_, .01); @@ -1267,18 +1267,18 @@ int Cvode::interpolate(double tout) { // The fudge case was avoided by returning from the // Cvode::handle_step when a first order condition check // puts an event on the queue equal to t_ - Printf("Cvode::interpolate assert error t0=%g tout-t0=%g eps*t_=%g\n", - t0_, - tout - t0_, - NetCvode::eps(t_)); + logger.print("Cvode::interpolate assert error t0={} tout-t0={} eps*t_={}\n", + t0_, + tout - t0_, + NetCvode::eps(t_)); // } tout = t0_; } if (tout > tn_) { - Printf("Cvode::interpolate assert error tn=%g tn-tout=%g eps*t_=%g\n", - tn_, - tn_ - tout, - NetCvode::eps(t_)); + logger.print("Cvode::interpolate assert error tn={} tn-tout={} eps*t_={}\n", + tn_, + tn_ - tout, + NetCvode::eps(t_)); tout = tn_; } #endif @@ -1301,12 +1301,12 @@ int Cvode::interpolate(double tout) { int Cvode::cvode_advance_tn(neuron::model_sorted_token const& sorted_token) { #if PRINT_EVENT if (net_cvode_instance->print_event_ > 1) { - Printf("Cvode::cvode_advance_tn %p %d initialize_=%d tstop=%.20g t_=%.20g to ", - fmt::ptr(this), - nth_ ? nth_->id : 0, - initialize_, - tstop_, - t_); + logger.print("Cvode::cvode_advance_tn {} {} initialize_={} tstop={:.20g} t_={:.20g} to ", + fmt::ptr(this), + nth_ ? nth_->id : 0, + initialize_, + tstop_, + t_); } #endif std::pair opaque{this, sorted_token}; @@ -1317,14 +1317,14 @@ int Cvode::cvode_advance_tn(neuron::model_sorted_token const& sorted_token) { CVodeSetFdata(mem_, nullptr); #if PRINT_EVENT if (net_cvode_instance->print_event_ > 1) { - Printf("t_=%.20g\n", t_); + logger.print("t_={:.20g}\n", t_); } #endif if (err < 0) { - Printf("CVode %p %s advance_tn failed, err=%d.\n", - fmt::ptr(this), - secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), - err); + logger.print("CVode {} {} advance_tn failed, err={}.\n", + fmt::ptr(this), + secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), + err); pf_(t_, y_, nullptr, &opaque); return err; } @@ -1343,11 +1343,11 @@ int Cvode::cvode_advance_tn(neuron::model_sorted_token const& sorted_token) { int Cvode::cvode_interpolate(double tout) { #if PRINT_EVENT if (net_cvode_instance->print_event_ > 1) { - Printf("Cvode::cvode_interpolate %p %d initialize_%d t=%.20g to ", - fmt::ptr(this), - nth_ ? nth_->id : 0, - initialize_, - t_); + logger.print("Cvode::cvode_interpolate {} {} initialize_{} t={:.20g} to ", + fmt::ptr(this), + nth_ ? nth_->id : 0, + initialize_, + t_); } #endif // avoid CVode-- tstop = 0.5 is behind current t = 0.5 @@ -1360,14 +1360,14 @@ int Cvode::cvode_interpolate(double tout) { CVodeSetFdata(mem_, nullptr); #if PRINT_EVENT if (net_cvode_instance->print_event_ > 1) { - Printf("%.20g\n", t_); + logger.print("{:.20g}\n", t_); } #endif if (err < 0) { - Printf("CVode %p %s interpolate failed, err=%d.\n", - fmt::ptr(this), - secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), - err); + logger.print("CVode {} {} interpolate failed, err={}.\n", + fmt::ptr(this), + secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), + err); return err; } pf_(t_, y_, nullptr, &opaque); @@ -1408,35 +1408,35 @@ N_Vector Cvode::acorvec() { void Cvode::statistics() { #if 1 - Printf("\nCvode instance %p %s statistics : %d %s states\n", - fmt::ptr(this), - secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), - neq_, - (use_daspk_ ? "IDA" : "CVode")); - Printf(" %d advance_tn, %d interpolate, %d init (%d due to at_time)\n", - advance_calls_, - interpolate_calls_, - init_calls_, - ts_inits_); - Printf(" %d function evaluations, %d mx=b solves, %d jacobian setups\n", - f_calls_, - mxb_calls_, - jac_calls_); + logger.print("\nCvode instance {} {} statistics : {} {} states\n", + fmt::ptr(this), + secname(ctd_[0].v_node_[ctd_[0].rootnodecount_]->sec), + neq_, + (use_daspk_ ? "IDA" : "CVode")); + logger.print(" {} advance_tn, {} interpolate, {} init ({} due to at_time)\n", + advance_calls_, + interpolate_calls_, + init_calls_, + ts_inits_); + logger.print(" {} function evaluations, {} mx=b solves, {} jacobian setups\n", + f_calls_, + mxb_calls_, + jac_calls_); if (use_daspk_) { daspk_->statistics(); return; } #else - Printf("\nCVode Statistics.. \n\n"); - Printf("internal steps = %d\nfunction evaluations = %d\n", iopt_[NST], iopt_[NFE]); - Printf( - "newton iterations = %d setups = %d\n nonlinear convergence failures = %d\n\ - local error test failures = %ld\n", + logger.print("\nCVode Statistics.. \n\n"); + logger.print("internal steps = {}\nfunction evaluations = {}\n", iopt_[NST], iopt_[NFE]); + logger.print( + "newton iterations = {} setups = {}\n nonlinear convergence failures = {}\n\ + local error test failures = {}\n", iopt_[NNI], iopt_[NSETUPS], iopt_[NCFN], iopt_[NETF]); - Printf("order=%d stepsize=%g\n", iopt_[QU], h()); + logger.print("order={} stepsize={}\n", iopt_[QU], h()); #endif } diff --git a/src/nrncvode/netcvode.cpp b/src/nrncvode/netcvode.cpp index b64feb7494..10ca6fbee6 100644 --- a/src/nrncvode/netcvode.cpp +++ b/src/nrncvode/netcvode.cpp @@ -1040,12 +1040,12 @@ void NetCvodeThreadData::interthread_send(double td, DiscreteEvent* db, NrnThrea MUTLOCK #if PRINT_EVENT if (net_cvode_instance->print_event_) { - Printf("interthread send td=%.15g DE type=%d thread=%d target=%d %s\n", - td, - db->type(), - nt->id, - (db->type() == 2) ? PP2NT(((NetCon*) db)->target_)->id : -1, - (db->type() == 2) ? hoc_object_name(((NetCon*) (db))->target_->ob) : "?"); + logger.print("interthread send td={:.15g} DE type={} thread={} target={} {}\n", + td, + db->type(), + nt->id, + (db->type() == 2) ? PP2NT(((NetCon*) db)->target_)->id : -1, + (db->type() == 2) ? hoc_object_name(((NetCon*) (db))->target_->ob) : "?"); } #endif if (ite_cnt_ >= ite_size_) { @@ -1078,13 +1078,14 @@ void NetCvodeThreadData::enqueue(NetCvode* nc, NrnThread* nt) { InterThreadEvent& ite = inter_thread_events_[i]; #if PRINT_EVENT if (net_cvode_instance->print_event_) { - Printf("interthread enqueue td=%.15g DE type=%d thread=%d target=%d %s\n", - ite.t_, - ite.de_->type(), - nt->id, - (ite.de_->type() == 2) ? PP2NT(((NetCon*) (ite.de_))->target_)->id : -1, - (ite.de_->type() == 2) ? hoc_object_name(((NetCon*) (ite.de_))->target_->ob) - : "?"); + logger.print("interthread enqueue td={:.15g} DE type={} thread={} target={} {}\n", + ite.t_, + ite.de_->type(), + nt->id, + (ite.de_->type() == 2) ? PP2NT(((NetCon*) (ite.de_))->target_)->id : -1, + (ite.de_->type() == 2) + ? hoc_object_name(((NetCon*) (ite.de_))->target_->ob) + : "?"); } #endif nc->bin_event(ite.t_, ite.de_, nt); @@ -2223,11 +2224,11 @@ void NetCvode::move_event(TQItem* q, double tnew, NrnThread* nt) { #if PRINT_EVENT if (print_event_) { SelfEvent* se = (SelfEvent*) q->data_; - Printf("NetCvode::move_event self event target %s t=%g, old=%g new=%g\n", - hoc_object_name(se->target_->ob), - nt->_t, - q->t_, - tnew); + logger.print("NetCvode::move_event self event target {} t={}, old={} new={}\n", + hoc_object_name(se->target_->ob), + nt->_t, + q->t_, + tnew); } #endif p[tid].tqe_->move(q, tnew); @@ -2921,7 +2922,7 @@ void DiscreteEvent::pgvts_deliver(double tt, NetCvode* ns) { } void DiscreteEvent::pr(const char* s, double tt, NetCvode* ns) { - Printf("%s DiscreteEvent %.15g\n", s, tt); + logger.print("{} DiscreteEvent {:.15g}\n", s, tt); } void NetCon::send(double tt, NetCvode* ns, NrnThread* nt) { @@ -2941,7 +2942,7 @@ void NetCon::deliver(double tt, NetCvode* ns, NrnThread* nt) { ss += memb_func[type].sym->name; nrn::Instrumentor::phase p_get_pnt_receive(ss.c_str()); if (PP2NT(target_) != nt) { - Printf("NetCon::deliver nt=%d target=%d\n", nt->id, PP2NT(target_)->id); + logger.print("NetCon::deliver nt={} target={}\n", nt->id, PP2NT(target_)->id); } assert(PP2NT(target_) == nt); Cvode* cv = (Cvode*) target_->nvi_; @@ -2990,13 +2991,13 @@ void NetCon::pgvts_deliver(double tt, NetCvode* ns) { } void NetCon::pr(const char* s, double tt, NetCvode* ns) { - Printf("%s %s", s, hoc_object_name(obj_)); + logger.print("{} {}", s, hoc_object_name(obj_)); if (src_) { - Printf(" src=%s", src_->osrc_ ? hoc_object_name(src_->osrc_) : secname(src_->ssrc_)); + logger.print(" src={}", src_->osrc_ ? hoc_object_name(src_->osrc_) : secname(src_->ssrc_)); } else { - Printf(" src=nullptr"); + logger.print(" src=nullptr"); } - Printf(" target=%s %.15g\n", (target_ ? hoc_object_name(target_->ob) : "nullptr"), tt); + logger.print(" target={} {:.15g}\n", (target_ ? hoc_object_name(target_->ob) : "nullptr"), tt); } void PreSyn::send(double tt, NetCvode* ns, NrnThread* nt) { @@ -3133,9 +3134,9 @@ void PreSyn::pgvts_deliver(double tt, NetCvode* ns) { } void PreSyn::pr(const char* s, double tt, NetCvode* ns) { - Printf("%s", s); - Printf(" PreSyn src=%s", osrc_ ? hoc_object_name(osrc_) : secname(ssrc_)); - Printf(" %.15g\n", tt); + logger.print("{}", s); + logger.print(" PreSyn src={}", osrc_ ? hoc_object_name(osrc_) : secname(ssrc_)); + logger.print(" {:.15g}\n", tt); } SelfEvent::SelfEvent() {} @@ -3276,8 +3277,8 @@ void SelfEvent::call_net_receive(NetCvode* ns) { } void SelfEvent::pr(const char* s, double tt, NetCvode* ns) { - Printf("%s", s); - Printf(" SelfEvent target=%s %.15g flag=%g\n", hoc_object_name(target_->ob), tt, flag_); + logger.print("{}", s); + logger.print(" SelfEvent target={} {:.15g} flag={}\n", hoc_object_name(target_->ob), tt, flag_); } void PlayRecordEvent::frecord_init(TQItem* q) { @@ -3298,7 +3299,7 @@ NrnThread* PlayRecordEvent::thread() { } void PlayRecordEvent::pr(const char* s, double tt, NetCvode* ns) { - Printf("%s PlayRecordEvent %.15g ", s, tt); + logger.print("{} PlayRecordEvent {:.15g} ", s, tt); plr_->pr(); } @@ -3318,7 +3319,7 @@ HocEvent::~HocEvent() { } void HocEvent::pr(const char* s, double tt, NetCvode* ns) { - Printf("%s HocEvent %s %.15g\n", s, stmt_ ? stmt_->name() : "", tt); + logger.print("{} HocEvent {} {:.15g}\n", s, stmt_ ? stmt_->name() : "", tt); } HocEvent* HocEvent::alloc(const char* stmt, Object* ppobj, int reinit, Object* pyact) { @@ -3491,21 +3492,21 @@ void NetCvode::local_retreat(double t, Cvode* cv) { if (tq) { #if PRINT_EVENT if (print_event_) { - Printf("microstep local retreat from %g (cvode_%p is at %g) for event onset=%g\n", - cv->tqitem_->t_, - fmt::ptr(cv), - cv->t_, - t); + logger.print("microstep local retreat from {} (cvode_{} is at {}) for event onset={}\n", + cv->tqitem_->t_, + fmt::ptr(cv), + cv->t_, + t); } #endif cv->interpolate(t); tq->move(cv->tqitem_, t); #if PRINT_EVENT if (print_event_ > 1) { - Printf("after target solve time for %p is %g , dt=%g\n", - fmt::ptr(cv), - cv->time(), - nt_dt); + logger.print("after target solve time for {} is {} , dt={}\n", + fmt::ptr(cv), + cv->time(), + nt_dt); } #endif } else { @@ -3520,11 +3521,11 @@ void NetCvode::retreat(double t, Cvode* cv) { TQueue* tq = p[cv->nth_ ? cv->nth_->id : 0].tq_; #if PRINT_EVENT if (print_event_) { - Printf("microstep retreat from %g (cvode_%p is at %g) for event onset=%g\n", - tq ? cv->tqitem_->t_ : cv->t_, - fmt::ptr(cv), - cv->t_, - t); + logger.print("microstep retreat from {:g} (cvode_{} is at {:g}) for event onset={}\n", + tq ? cv->tqitem_->t_ : cv->t_, + fmt::ptr(cv), + cv->t_, + t); } #endif cv->interpolate(t); @@ -3533,7 +3534,10 @@ void NetCvode::retreat(double t, Cvode* cv) { } #if PRINT_EVENT if (print_event_ > 1) { - Printf("after target solve time for %p is %g , dt=%g\n", fmt::ptr(cv), cv->time(), dt); + logger.print("after target solve time for {} is {} , dt={}\n", + fmt::ptr(cv), + cv->time(), + dt); } #endif } @@ -3829,13 +3833,13 @@ void NetCvode::statistics(int i) { } } } - Printf("NetCon active=%lu (not sent)=%lu delivered=%lu\n", - NetCon::netcon_send_active_, - NetCon::netcon_send_inactive_, - NetCon::netcon_deliver_); - Printf( - "Condition O2 thresh detect=%lu via init=%lu effective=%lu abandoned=%lu (unnecesarily=%lu " - "init+=%lu init-=%lu above=%lu below=%lu)\n", + logger.print("NetCon active={} (not sent)={} delivered={}\n", + NetCon::netcon_send_active_, + NetCon::netcon_send_inactive_, + NetCon::netcon_deliver_); + logger.print( + "Condition O2 thresh detect={} via init={} effective={} abandoned={} (unnecesarily={} " + "init+={} init-={} above={} below={})\n", ConditionEvent::send_qthresh_, ConditionEvent::init_above_, ConditionEvent::deliver_qthresh_, @@ -3845,38 +3849,38 @@ void NetCvode::statistics(int i) { ConditionEvent::abandon_init_below_, ConditionEvent::abandon_above_, ConditionEvent::abandon_below_); - Printf("PreSyn send: mindelay=%lu direct=%lu\n", - PreSyn::presyn_send_mindelay_, - PreSyn::presyn_send_direct_); - Printf("PreSyn deliver: O2 thresh=%lu NetCon=%lu (send=%lu deliver=%lu)\n", - ConditionEvent::deliver_qthresh_, - PreSyn::presyn_deliver_netcon_, - PreSyn::presyn_deliver_ncsend_, - PreSyn::presyn_deliver_direct_); - Printf("SelfEvent send=%lu move=%lu deliver=%lu\n", - SelfEvent::selfevent_send_, - SelfEvent::selfevent_move_, - SelfEvent::selfevent_deliver_); - Printf("Watch send=%lu deliver=%lu\n", - WatchCondition::watch_send_, - WatchCondition::watch_deliver_); - Printf("PlayRecord send=%lu deliver=%lu\n", - PlayRecordEvent::playrecord_send_, - PlayRecordEvent::playrecord_deliver_); - Printf("HocEvent send=%lu deliver=%lu\n", - HocEvent::hocevent_send_, - HocEvent::hocevent_deliver_); - Printf("SingleEvent deliver=%lu move=%lu\n", - KSSingle::singleevent_deliver_, - KSSingle::singleevent_move_); - Printf("DiscreteEvent send=%lu deliver=%lu\n", - DiscreteEvent::discretevent_send_, - DiscreteEvent::discretevent_deliver_); - Printf("%lu total events delivered net_event=%lu\n", deliver_cnt_, net_event_cnt_); - Printf("Discrete event TQueue\n"); + logger.print("PreSyn send: mindelay={} direct={}\n", + PreSyn::presyn_send_mindelay_, + PreSyn::presyn_send_direct_); + logger.print("PreSyn deliver: O2 thresh={} NetCon={} (send={} deliver={})\n", + ConditionEvent::deliver_qthresh_, + PreSyn::presyn_deliver_netcon_, + PreSyn::presyn_deliver_ncsend_, + PreSyn::presyn_deliver_direct_); + logger.print("SelfEvent send={} move={} deliver={}\n", + SelfEvent::selfevent_send_, + SelfEvent::selfevent_move_, + SelfEvent::selfevent_deliver_); + logger.print("Watch send={} deliver={}\n", + WatchCondition::watch_send_, + WatchCondition::watch_deliver_); + logger.print("PlayRecord send={} deliver={}\n", + PlayRecordEvent::playrecord_send_, + PlayRecordEvent::playrecord_deliver_); + logger.print("HocEvent send={} deliver={}\n", + HocEvent::hocevent_send_, + HocEvent::hocevent_deliver_); + logger.print("SingleEvent deliver={} move={}\n", + KSSingle::singleevent_deliver_, + KSSingle::singleevent_move_); + logger.print("DiscreteEvent send={} deliver={}\n", + DiscreteEvent::discretevent_send_, + DiscreteEvent::discretevent_deliver_); + logger.print("{} total events delivered net_event={}\n", deliver_cnt_, net_event_cnt_); + logger.print("Discrete event TQueue\n"); p[0].tqe_->statistics(); if (p[0].tq_) { - Printf("Variable step integrator TQueue\n"); + logger.print("Variable step integrator TQueue\n"); p[0].tq_->statistics(); } } @@ -4666,7 +4670,7 @@ DiscreteEvent* DiscreteEvent::savestate_save() { void DiscreteEvent::savestate_restore(double tt, NetCvode* nc) { // pr("savestate_restore", tt, nc); - Printf("null_event_ onto queue\n"); + logger.print("null_event_ onto queue\n"); nc->null_event(tt); } @@ -5247,7 +5251,7 @@ void ConditionEvent::abandon_statistics(Cvode* cv) { // take fastidiousness to // an extreme STATISTICS(eq_abandon_); - Printf("abandon when t == qthresh_->t_ = %20.15g\n", nt_t); + logger.print("abandon when t == qthresh_->t_ = {:20.15g}\n", nt_t); } if (cv->t0_ == cv->tn_) { // inited if (value() > 0.0) { // above threshold @@ -5456,8 +5460,8 @@ void STECondition::pgvts_deliver(double tt, NetCvode* ns) { } void WatchCondition::pr(const char* s, double tt, NetCvode* ns) { - Printf("%s", s); - Printf(" WatchCondition %s %.15g flag=%g\n", hoc_object_name(pnt_->ob), tt, nrflag_); + logger.print("{}", s); + logger.print(" WatchCondition {} {:.15g} flag={}\n", hoc_object_name(pnt_->ob), tt, nrflag_); } static Cvode* eval_cv; @@ -5578,10 +5582,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(pd)), - pr->type()); + logger.error("Pointer {} of PlayRecord type {} ignored because not a Range Variable", + fmt::ptr(static_cast(pd)), + pr->type()); } } return err; @@ -6095,7 +6098,7 @@ void PlayRecord::play_add(Cvode* cv) { } void PlayRecord::pr() { - Printf("PlayRecord\n"); + logger.print("PlayRecord\n"); } TvecRecord::TvecRecord(Section* sec, IvocVect* t, Object* ppobj) diff --git a/src/nrncvode/nrndaspk.cpp b/src/nrncvode/nrndaspk.cpp index 5434cdc031..2eabaf3a33 100644 --- a/src/nrncvode/nrndaspk.cpp +++ b/src/nrncvode/nrndaspk.cpp @@ -207,7 +207,7 @@ static void do_ode_thread(neuron::model_sorted_token const& sorted_token, NrnThr static double check(double t, Daspk* ida) { res_gvardt(t, ida->cv_->y_, ida->yp_, ida->delta_, ida->cv_); double norm = N_VWrmsNorm(ida->delta_, ((IDAMem) (ida->mem_))->ida_ewt); - Printf("ida check t=%.15g norm=%g\n", t, norm); + logger.print("ida check t={:.15g} norm={}\n", t, norm); #if 0 for (int i=0; i < ida->cv_->neq_; ++i) { printf(" %3d %22.15g %22.15g %22.15g\n", i, @@ -287,17 +287,19 @@ cv_->t_, t-cv_->t_, cv_->t0_-cv_->t_); if (norm > 1.) { switch (init_failure_style_ & 03) { case 0: - Printf("IDA initialization failure, weighted norm of residual=%g\n", norm); + logger.print("IDA initialization failure, weighted norm of residual={}\n", norm); return IDA_ERR_FAIL; break; case 1: - Printf("IDA initialization warning, weighted norm of residual=%g\n", norm); + logger.print("IDA initialization warning, weighted norm of residual={}\n", norm); break; case 2: - Printf("IDA initialization warning, weighted norm of residual=%g\n", norm); + logger.print("IDA initialization warning, weighted norm of residual={}\n", norm); use_parasite_ = true; t_parasite_ = nt_t; - Printf(" subtracting (for next 1e-6 ms): f(y', y, %g)*exp(-1e7*(t-%g))\n", nt_t, nt_t); + logger.print(" subtracting (for next 1e-6 ms): f(y', y, {})*exp(-1e7*(t-{}))\n", + nt_t, + nt_t); break; } #if 0 @@ -350,7 +352,7 @@ int Daspk::interpolate(double tt) { assert(tt >= cv_->t0_ && tt <= cv_->tn_); int ier = IDAGetSolution(mem_, tt, cv_->y_, yp_); if (ier < 0) { - Printf("DASPK interpolate error\n"); + logger.print("DASPK interpolate error\n"); return ier; } cv_->t_ = tt; @@ -379,7 +381,7 @@ void Daspk::statistics() { printf("linear conv. failures = %d\n", iwork_[16-1]); #endif if (first_try_init_failures_) { - Printf(" %d First try Initialization failures\n", first_try_init_failures_); + logger.print(" {} First try Initialization failures\n", first_try_init_failures_); } } diff --git a/src/nrncvode/tqueue.cpp b/src/nrncvode/tqueue.cpp index ffc7c8e2ef..bf78a9f3a4 100644 --- a/src/nrncvode/tqueue.cpp +++ b/src/nrncvode/tqueue.cpp @@ -46,14 +46,14 @@ void (*nrn_binq_enqueue_error_handler)(double, TQItem*); static void prnt(const TQItem* b, int level) { int i; for (i = 0; i < level; ++i) { - Printf(" "); - } - Printf("%g %c %d Q=%p D=%p\n", - b->t_, - b->data_ ? 'x' : 'o', - b->cnt_, - fmt::ptr(b), - fmt::ptr(b->data_)); + logger.print(" "); + } + logger.print("{} {} {} Q={} D={}\n", + b->t_, + b->data_ ? 'x' : 'o', + b->cnt_, + fmt::ptr(b), + fmt::ptr(b->data_)); } TQueue::TQueue(TQItemPool* tp, int mkmut) { @@ -165,15 +165,12 @@ void TQueue::move(TQItem* i, double tnew) { void TQueue::statistics() { #if COLLECT_TQueue_STATISTICS - Printf("insertions=%lu moves=%lu removals=%lu calls to least=%lu\n", - ninsert, - nmove, - nrem, - nleast); - Printf("calls to find=%lu\n", nfind); - Printf("comparisons=%d\n", sptree_->get_enqcmps()); + logger.print( + "insertions={} moves={} removals={} calls to least={}\n", ninsert, nmove, nrem, nleast); + logger.print("calls to find={}\n", nfind); + logger.print("comparisons={}\n", sptree_->get_enqcmps()); #else - Printf("Turn on COLLECT_TQueue_STATISTICS_ in tqueue.hpp\n"); + logger.print("Turn on COLLECT_TQueue_STATISTICS_ in tqueue.hpp\n"); #endif } diff --git a/src/nrniv/cxprop.cpp b/src/nrniv/cxprop.cpp index 08921d655b..b984b6c9bf 100644 --- a/src/nrniv/cxprop.cpp +++ b/src/nrniv/cxprop.cpp @@ -114,15 +114,15 @@ void nrn_poolshrink(int shrink) { } neuron::model().shrink_to_fit(); } else { - Printf("poolshrink --- type name (dbluse, size) (datumuse, size)\n"); + logger.print("poolshrink --- type name (dbluse, size) (datumuse, size)\n"); for (auto i = 0; i < datumpools().size(); ++i) { auto const& pdatum = datumpools()[i]; if (pdatum) { - Printf("%d %s (%ld, %d)\n", - i, - (memb_func[i].sym ? memb_func[i].sym->name : "noname"), - (pdatum ? pdatum->nget() : 0), - (pdatum ? pdatum->size() : 0)); + logger.print("{} {} ({}, {})\n", + i, + (memb_func[i].sym ? memb_func[i].sym->name : "noname"), + (pdatum ? pdatum->nget() : 0), + (pdatum ? pdatum->size() : 0)); } } } diff --git a/src/nrniv/finithnd.cpp b/src/nrniv/finithnd.cpp index d29e0b4864..7a855275d0 100644 --- a/src/nrniv/finithnd.cpp +++ b/src/nrniv/finithnd.cpp @@ -40,14 +40,16 @@ static double allprint(void* v) { for (int type = 0; type < 4; ++type) { std::vector fl = FInitialHandler::fihlist_[type]; if (!fl.empty()) { - Printf("Type %d FInitializeHandler statements\n", type); + logger.print("Type {} FInitializeHandler statements\n", type); for (auto& f: fl) { if (f->stmt_->pyobject()) { - Printf("\t%s\n", hoc_object_name(f->stmt_->pyobject())); + logger.print("\t{}\n", hoc_object_name(f->stmt_->pyobject())); } else if (f->stmt_->object()) { - Printf("\t%s.%s\n", hoc_object_name(f->stmt_->object()), f->stmt_->name()); + logger.print("\t{}.{}\n", + hoc_object_name(f->stmt_->object()), + f->stmt_->name()); } else { - Printf("\t%s\n", f->stmt_->name()); + logger.print("\t{}\n", f->stmt_->name()); } } } diff --git a/src/nrniv/kschan.cpp b/src/nrniv/kschan.cpp index a5c8fc8a86..d324bde496 100644 --- a/src/nrniv/kschan.cpp +++ b/src/nrniv/kschan.cpp @@ -635,53 +635,55 @@ static double ks_pr(void* v) { KSChan* ks = (KSChan*) v; KSTransition* kt; - Printf("%s type properties\n", hoc_object_name(ks->obj_)); - Printf("name=%s is_point_=%s ion_=%s cond_model_=%d\n", - ks->name_.c_str(), - (ks->is_point() ? "true" : "false"), - ks->ion_.c_str(), - ks->cond_model_); - Printf(" ngate=%d nstate=%d nhhstate=%d nligand=%d ntrans=%d ivkstrans=%d iligtrans=%d\n", - ks->ngate_, - ks->nstate_, - ks->nhhstate_, - ks->nligand_, - ks->ntrans_, - ks->ivkstrans_, - ks->iligtrans_); - Printf(" default gmax=%g erev=%g\n", ks->gmax_deflt_, ks->erev_deflt_); + logger.print("{} type properties\n", hoc_object_name(ks->obj_)); + logger.print("name={} is_point_={} ion_={} cond_model_={}\n", + ks->name_, + (ks->is_point() ? "true" : "false"), + ks->ion_, + ks->cond_model_); + logger.print( + " ngate={} nstate={} nhhstate={} nligand={} ntrans={} ivkstrans={} iligtrans={}\n", + ks->ngate_, + ks->nstate_, + ks->nhhstate_, + ks->nligand_, + ks->ntrans_, + ks->ivkstrans_, + ks->iligtrans_); + logger.print(" default gmax={} erev={}\n", ks->gmax_deflt_, ks->erev_deflt_); for (int i = 0; i < ks->ngate_; ++i) { - Printf(" gate %d index=%d nstate=%d power=%d\n", - i, - ks->gc_[i].sindex_, - ks->gc_[i].nstate_, - ks->gc_[i].power_); + logger.print(" gate {} index={} nstate={} power={}\n", + i, + ks->gc_[i].sindex_, + ks->gc_[i].nstate_, + ks->gc_[i].power_); } for (int i = 0; i < ks->nligand_; ++i) { - Printf(" ligand %d %s\n", i, ks->ligands_[i]->name); + logger.print(" ligand {} {}\n", i, ks->ligands_[i]->name); } for (int i = 0; i < ks->iligtrans_; ++i) { kt = ks->trans_ + i; - Printf(" trans %d src=%d target=%d type=%d\n", i, kt->src_, kt->target_, kt->type_); - Printf(" f0 type=%d f1 type=%d\n", - kt->f0 ? kt->f0->type() : -1, - kt->f1 ? kt->f1->type() : -1); + logger.print( + " trans {} src={} target={} type={}\n", i, kt->src_, kt->target_, kt->type_); + logger.print(" f0 type={} f1 type={}\n", + kt->f0 ? kt->f0->type() : -1, + kt->f1 ? kt->f1->type() : -1); } for (int i = ks->iligtrans_; i < ks->ntrans_; ++i) { kt = ks->trans_ + i; - Printf(" trans %d src=%d target=%d type=%d ligindex=%d\n", - i, - kt->src_, - kt->target_, - kt->type_, - kt->ligand_index_); - Printf(" f0 type=%d f1 type=%d\n", - kt->f0 ? kt->f0->type() : -1, - kt->f1 ? kt->f1->type() : -1); - } - Printf(" state names and fractional conductance\n"); + logger.print(" trans {} src={} target={} type={} ligindex={}\n", + i, + kt->src_, + kt->target_, + kt->type_, + kt->ligand_index_); + logger.print(" f0 type={} f1 type={}\n", + kt->f0 ? kt->f0->type() : -1, + kt->f1 ? kt->f1->type() : -1); + } + logger.print(" state names and fractional conductance\n"); for (int i = 0; i < ks->nstate_; ++i) { - Printf(" %d %s %g\n", i, ks->state_[i].string(), ks->state_[i].f_); + logger.print(" {} {} {}\n", i, ks->state_[i].string(), ks->state_[i].f_); } return 1; } @@ -952,7 +954,7 @@ void KSChan::setname(const char* s) { char old_suffix[100]; int i = 0; while (strcmp(mechsym_->name, name_.c_str()) != 0 && looksym(name_.c_str())) { - Printf("KSChan::setname %s already in use\n", name_.c_str()); + logger.print("KSChan::setname {} already in use\n", name_); Sprintf(old_suffix, "%s%d", s, i); name_ = old_suffix; ++i; @@ -1211,7 +1213,7 @@ void KSChan::setion(const char* s) { Symbol* sym = looksym(buf); if (!sym || sym->type != MECHANISM || memb_func[sym->subtype].alloc != memb_func[looksym("na_ion")->subtype].alloc) { - Printf("%s is not an ion mechanism", sym->name); + logger.print("{} is not an ion mechanism", sym->name); } if (ion_sym_) { // there already is an ion if (strcmp(ion_sym_->name, buf) != 0) { // is it different diff --git a/src/nrniv/kssingle.cpp b/src/nrniv/kssingle.cpp index f23267ee33..bf337dc9cb 100644 --- a/src/nrniv/kssingle.cpp +++ b/src/nrniv/kssingle.cpp @@ -233,7 +233,7 @@ void KSSingleNodeData::deliver(double tt, NetCvode* nc, NrnThread* nt) { } void KSSingleNodeData::pr(const char* s, double tt, NetCvode* nc) { - Printf("%s %s %.15g\n", s, hoc_object_name((*ppnt_)->ob), tt); + logger.print("{} {} {:.15g}\n", s, hoc_object_name((*ppnt_)->ob), tt); } void KSSingle::state(Node* nd, Datum* pd, NrnThread* nt) { diff --git a/src/nrniv/memory_usage.cpp b/src/nrniv/memory_usage.cpp index 49361bbd67..2609a994dd 100644 --- a/src/nrniv/memory_usage.cpp +++ b/src/nrniv/memory_usage.cpp @@ -137,7 +137,7 @@ std::string format_memory_usage(const MemoryUsage& usage) { void print_memory_usage(MemoryUsage const& memory_usage) { - Printf(fmt::format("{}\n", format_memory_usage(memory_usage)).c_str()); + logger.print("{}\n", format_memory_usage(memory_usage)); } } // namespace neuron::container diff --git a/src/nrniv/multisplit.cpp b/src/nrniv/multisplit.cpp index f9b9531d78..abf427cbda 100644 --- a/src/nrniv/multisplit.cpp +++ b/src/nrniv/multisplit.cpp @@ -1672,19 +1672,19 @@ void MultiSplitControl::pexch() { id = nrnmpi_myid; // assume only one thread when there is transfer info NrnThread* nt = nrn_threads; - Printf("%d nthost_=%d\n", id, nthost_); + logger.print("{} nthost_={}\n", id, nthost_); for (i = 0; i < nthost_; ++i) { MultiSplitTransferInfo& ms = msti_[i]; - Printf("%d %d host=%d nnode=%d displ=%d\n", id, i, ms.host_, ms.nnode_, ms.displ_); + logger.print("{} {} host={} nnode={} displ={}\n", id, i, ms.host_, ms.nnode_, ms.displ_); for (j = 0; j < ms.nnode_; ++j) { k = ms.nodeindex_[j]; - Printf("%d %d %d %d %s %d\n", - id, - i, - j, - k, - secname(nt->_v_node[k]->sec), - nt->_v_node[k]->sec_node_index_); + logger.print("{} {} {} {} {} {}\n", + id, + i, + j, + k, + secname(nt->_v_node[k]->sec), + nt->_v_node[k]->sec_node_index_); } } } @@ -1805,91 +1805,93 @@ void MultiSplitControl::prstruct() { for (id = 0; id < nrnmpi_numprocs; ++id) { nrnmpi_barrier(); if (id == nrnmpi_myid) { - Printf("myid=%d\n", id); - Printf(" MultiSplit %ld\n", multisplit_list_->size()); + logger.print("myid={}\n", id); + logger.print(" MultiSplit {}\n", multisplit_list_->size()); for (i = 0; i < multisplit_list_->size(); ++i) { MultiSplit* ms = (*multisplit_list_)[i]; - Printf(" %2d bbs=%d bi=%-2d rthost=%-4d %-4d %s{%d}", - i, - ms->backbone_style, - ms->back_index, - ms->rthost, - ms->sid[0], - secname(ms->nd[0]->sec), - ms->nd[0]->sec_node_index_); + logger.print(" {:2d} bbs={} bi={:-2d} rthost={:-4d} {:-4d} {}{{{}}}", + i, + ms->backbone_style, + ms->back_index, + ms->rthost, + ms->sid[0], + secname(ms->nd[0]->sec), + ms->nd[0]->sec_node_index_); if (ms->nd[1]) { - Printf(" %-4d %s{%d}", - ms->sid[1], - secname(ms->nd[1]->sec), - ms->nd[1]->sec_node_index_); + logger.print(" {:-4d} {}{{{}}}", + ms->sid[1], + secname(ms->nd[1]->sec), + ms->nd[1]->sec_node_index_); } - Printf("\n"); + logger.print("\n"); } for (it = 0; it < nrn_nthread; ++it) { NrnThread* _nt = nrn_threads + it; MultiSplitThread& t = mth_[it]; - Printf(" backbone_begin=%d backbone_long_begin=%d backbone_interior_begin=%d\n", - t.backbone_begin, - t.backbone_long_begin, - t.backbone_interior_begin); - Printf(" backbone_sid1_begin=%d backbone_long_sid1_begin=%d backbone_end=%d\n", - t.backbone_sid1_begin, - t.backbone_long_sid1_begin, - t.backbone_end); - Printf(" nbackrt_=%d i, backsid_[i], backAindex_[i], backBindex_[i]\n", - t.nbackrt_); + logger.print( + " backbone_begin={} backbone_long_begin={} backbone_interior_begin={}\n", + t.backbone_begin, + t.backbone_long_begin, + t.backbone_interior_begin); + logger.print( + " backbone_sid1_begin={} backbone_long_sid1_begin={} backbone_end={}\n", + t.backbone_sid1_begin, + t.backbone_long_sid1_begin, + t.backbone_end); + logger.print(" nbackrt_={} i, backsid_[i], backAindex_[i], backBindex_[i]\n", + t.nbackrt_); if (t.nbackrt_) { for (int i = 0; i < t.nbackrt_; ++i) { - Printf(" %2d %2d %5d %5d", - i, - t.backsid_[i], - t.backAindex_[i], - t.backBindex_[i]); + logger.print(" {:2d} {:2d} {:5d} {:5d}", + i, + t.backsid_[i], + t.backAindex_[i], + t.backBindex_[i]); Node* nd = _nt->_v_node[t.backbone_begin + t.backAindex_[i]]; - Printf(" %s{%d}", secname(nd->sec), nd->sec_node_index_); + logger.print(" {}{{{}}}", secname(nd->sec), nd->sec_node_index_); nd = _nt->_v_node[t.backbone_begin + t.backBindex_[i]]; - Printf(" %s{%d}", secname(nd->sec), nd->sec_node_index_); - Printf("\n"); + logger.print(" {}{{{}}}", secname(nd->sec), nd->sec_node_index_); + logger.print("\n"); } } } - Printf(" ReducedTree %d\n", nrtree_); + logger.print(" ReducedTree {}\n", nrtree_); for (i = 0; i < nrtree_; ++i) { ReducedTree* rt = rtree_[i]; - Printf(" %d n=%d nmap=%d\n", i, rt->n, rt->nmap); + logger.print(" {} n={} nmap={}\n", i, rt->n, rt->nmap); rt->pr_map(tbsize, trecvbuf_); } - Printf(" MultiSplitTransferInfo %d\n", nthost_); + logger.print(" MultiSplitTransferInfo {}\n", nthost_); for (i = 0; i < nthost_; ++i) { MultiSplitTransferInfo& m = msti_[i]; - Printf(" %d host=%d rthost=%d nnode=%d nnode_rt=%d size=%d tag=%d\n", - i, - m.host_, - m.rthost_, - m.nnode_, - m.nnode_rt_, - m.size_, - m.tag_); + logger.print(" {} host={} rthost={} nnode={} nnode_rt={} size={} tag={}\n", + i, + m.host_, + m.rthost_, + m.nnode_, + m.nnode_rt_, + m.size_, + m.tag_); if (m.nnode_) { - Printf(" nodeindex=%p nodeindex_buffer = %p\n", - fmt::ptr(m.nodeindex_), - fmt::ptr(nodeindex_buffer_)); + logger.print(" nodeindex={} nodeindex_buffer = {}\n", + fmt::ptr(m.nodeindex_), + fmt::ptr(nodeindex_buffer_)); } } - Printf(" ndbsize=%d i nodeindex_buffer_=%p nodeindex_rthost_=%p\n", - ndbsize, - fmt::ptr(nodeindex_buffer_), - fmt::ptr(nodeindex_rthost_)); + logger.print(" ndbsize={} i nodeindex_buffer_={} nodeindex_rthost_={}\n", + ndbsize, + fmt::ptr(nodeindex_buffer_), + fmt::ptr(nodeindex_rthost_)); if (ndbsize) { for (int i = 0; i < ndbsize; ++i) { - Printf(" %d %d %d\n", i, nodeindex_buffer_[i], nodeindex_rthost_[i]); + logger.print(" {} {} {}\n", i, nodeindex_buffer_[i], nodeindex_rthost_[i]); } } - Printf(" tbsize=%d trecvbuf_=%p tsendbuf_=%p\n", - tbsize, - fmt::ptr(trecvbuf_), - fmt::ptr(tsendbuf_)); - Printf("\n"); + logger.print(" tbsize={} trecvbuf_={} tsendbuf_={}\n", + tbsize, + fmt::ptr(trecvbuf_), + fmt::ptr(tsendbuf_)); + logger.print("\n"); } } nrnmpi_barrier(); @@ -2666,53 +2668,53 @@ smap[i], *smap[i], smap[i+1], *smap[i+1]); void ReducedTree::pr_map(int tsize, double* trbuf) { int i; - Printf(" rmap\n"); + logger.print(" rmap\n"); for (i = 0; i < nmap; ++i) { for (int it = 0; it < nrn_nthread; ++it) { NrnThread* nt = nrn_threads + it; MultiSplitThread& t = msc_->mth_[it]; int nb = t.backbone_end - t.backbone_begin; if (rmap[i] >= trbuf && rmap[i] < (trbuf + tsize)) { - Printf(" %2d rhs[%2d] += tbuf[%ld]\n", i, irmap[i], rmap[i] - trbuf); + logger.print(" {:2d} rhs[{:2d}] += tbuf[{}]\n", i, irmap[i], rmap[i] - trbuf); } if (rmap[i] >= nt->node_rhs_storage() && rmap[i] < (nt->node_rhs_storage() + nt->end)) { Node* nd = nt->_v_node[rmap[i] - nt->node_rhs_storage()]; - Printf(" %2d rhs[%2d] rhs[%d] += rhs[%ld] \t%s{%d}\n", - i, - irmap[i], - irmap[i], - rmap[i] - nt->node_rhs_storage(), - secname(nd->sec), - nd->sec_node_index_); + logger.print(" {:2d} rhs[{:2d}] rhs[{}] += rhs[{}] \t{}{{{}}}\n", + i, + irmap[i], + irmap[i], + rmap[i] - nt->node_rhs_storage(), + secname(nd->sec), + nd->sec_node_index_); } if (rmap[i] >= nt->node_d_storage() && rmap[i] < (nt->node_d_storage() + nt->end)) { - Printf(" %2d rhs[%2d] d[%d] += d[%ld]\n", - i, - irmap[i], - irmap[i] - n, - rmap[i] - nt->node_d_storage()); + logger.print(" {:2d} rhs[{:2d}] d[{}] += d[{}]\n", + i, + irmap[i], + irmap[i] - n, + rmap[i] - nt->node_d_storage()); } if (rmap[i] >= t.sid1A && rmap[i] < (t.sid1A + nb)) { - Printf(" %2d rhs[%2d] a[%d] += sid1A[%ld]", - i, - irmap[i], - irmap[i] - 2 * n, - rmap[i] - t.sid1A); + logger.print(" {:2d} rhs[{:2d}] a[{}] += sid1A[{}]", + i, + irmap[i], + irmap[i] - 2 * n, + rmap[i] - t.sid1A); int j = (rmap[i] - t.sid1A) + t.backbone_begin; Node* nd = nt->_v_node[j]; - Printf(" \tA(%d) %s{%d}", j, secname(nd->sec), nd->sec_node_index_); - Printf("\n"); + logger.print(" \tA({}) {}{{{}}}", j, secname(nd->sec), nd->sec_node_index_); + logger.print("\n"); } if (rmap[i] >= t.sid1B && rmap[i] < (t.sid1B + nb)) { - Printf(" %2d rhs[%2d] b[%d] += sid1B[%ld]", - i, - irmap[i], - irmap[i] - 3 * n, - rmap[i] - t.sid1B); + logger.print(" {:2d} rhs[{:2d}] b[{}] += sid1B[{}]", + i, + irmap[i], + irmap[i] - 3 * n, + rmap[i] - t.sid1B); int j = (rmap[i] - t.sid1B) + t.backbone_begin; Node* nd = nt->_v_node[j]; - Printf("\tB(%d) %s{%d}", j, secname(nd->sec), nd->sec_node_index_); - Printf("\n"); + logger.print("\tB({}) {}{{{}}}", j, secname(nd->sec), nd->sec_node_index_); + logger.print("\n"); } } } @@ -3449,34 +3451,38 @@ for (i=i1; i < i3; ++i) { void MultiSplitControl::pmat(bool full) { int it, i, is; - Printf("\n"); + logger.print("\n"); for (it = 0; it < nrn_nthread; ++it) { NrnThread* _nt = nrn_threads + it; MultiSplitThread& t = mth_[it]; for (i = 0; i < _nt->end; ++i) { is = _nt->_v_node[i]->_classical_parent ? _nt->_v_node[i]->sec_node_index_ : -1; - Printf("%d %d %s %d", - _nt->_v_node[i]->v_node_index, - _nt->_v_parent[i] ? _nt->_v_parent[i]->v_node_index : -1, - secname(_nt->_v_node[i]->sec), - is); + logger.print("{} {} {} {}", + _nt->_v_node[i]->v_node_index, + _nt->_v_parent[i] ? _nt->_v_parent[i]->v_node_index : -1, + secname(_nt->_v_node[i]->sec), + is); if (_nt->_v_parent[i]) { is = _nt->_v_parent[i]->_classical_parent ? _nt->_v_parent[i]->sec_node_index_ : -1; - Printf(" -> %s %d", secname(_nt->_v_parent[i]->sec), is); - Printf("\t %10.5g %10.5g", NODEB(_nt->_v_node[i]), NODEA(_nt->_v_node[i])); + logger.print(" -> {} {}", secname(_nt->_v_parent[i]->sec), is); + logger.print("\t {:10.5g} {:10.5g}", + NODEB(_nt->_v_node[i]), + NODEA(_nt->_v_node[i])); } else { - Printf(" root\t\t %10.5g %10.5g", 0., 0.); + logger.print(" root\t\t {:10.5g} {:10.5g}", 0., 0.); } if (full) { - Printf(" %10.5g %10.5g", NODED(_nt->_v_node[i]), NODERHS(_nt->_v_node[i])); + logger.print(" {:10.5g} {:10.5g}", + NODED(_nt->_v_node[i]), + NODERHS(_nt->_v_node[i])); if (t.sid0i && i >= t.backbone_begin && i < t.backbone_end) { - Printf(" %10.5g %10.5g", - t.S1B(i - t.backbone_begin), - t.S1A(i - t.backbone_begin)); + logger.print(" {:10.5g} {:10.5g}", + t.S1B(i - t.backbone_begin), + t.S1A(i - t.backbone_begin)); } } - Printf("\n"); + logger.print("\n"); } } } @@ -3544,27 +3550,27 @@ void MultiSplitControl::pmat1(const char* s) { if (ms->nd[1]) { a = mth_[it].S1A(0); } - Printf("%2d %s sid=%d %12.5g %12.5g %12.5g %12.5g\n", - nrnmpi_myid, - s, - ms->sid[0], - b, - d, - a, - rhs); + logger.print("{:2d} {} sid={} {:12.5g} {:12.5g} {:12.5g} {:12.5g}\n", + nrnmpi_myid, + s, + ms->sid[0], + b, + d, + a, + rhs); if (ms->nd[1]) { d = D(ms->nd[1]->v_node_index); rhs = RHS(ms->nd[1]->v_node_index); a = 0.; b = t.S1B(t.backbone_sid1_begin - t.backbone_begin); - Printf("%2d %s sid=%d %12.5g %12.5g %12.5g %12.5g\n", - nrnmpi_myid, - s, - ms->sid[1], - b, - d, - a, - rhs); + logger.print("{:2d} {} sid={} {:12.5g} {:12.5g} {:12.5g} {:12.5g}\n", + nrnmpi_myid, + s, + ms->sid[1], + b, + d, + a, + rhs); } } } diff --git a/src/nrniv/netpar.cpp b/src/nrniv/netpar.cpp index 01dd711394..db3c7606e9 100644 --- a/src/nrniv/netpar.cpp +++ b/src/nrniv/netpar.cpp @@ -279,7 +279,8 @@ void NetParEvent::pgvts_deliver(double tt, NetCvode* nc) { } void NetParEvent::pr(const char* m, double tt, NetCvode* nc) { - Printf("%s NetParEvent %d t=%.15g tt-t=%g\n", m, ithread_, tt, tt - nrn_threads[ithread_]._t); + logger.print( + "{} NetParEvent {} t={:.15g} tt-t={:g}\n", m, ithread_, tt, tt - nrn_threads[ithread_]._t); } DiscreteEvent* NetParEvent::savestate_save() { @@ -1393,12 +1394,13 @@ static double set_mindelay(double maxdelay) { double od = mindelay_; mindelay = set_mindelay(maxdelay); if (nrnmpi_myid == 0) { - Printf( - "Notice: The global minimum NetCon delay is %g, so turned off the " + logger.print( + "Notice: The global minimum NetCon delay is {}, so turned off the " "cvode.queue_mode\n", od); - Printf(" use_self_queue option. The interprocessor minimum NetCon delay is %g\n", - mindelay); + logger.print( + " use_self_queue option. The interprocessor minimum NetCon delay is {}\n", + mindelay); } } errno = 0; @@ -1531,7 +1533,7 @@ int nrnmpi_spike_compress(int nspike, bool gid_compress, int xchng_meth) { // we can only do this after everything is set up mk_localgid_rep(); if (!nrn_use_localgid_ && nrnmpi_myid == 0) { - Printf( + logger.print( "Notice: gid compression did not succeed. Probably more than 255 cells on one " "cpu.\n"); } diff --git a/src/nrniv/neuronapi.cpp b/src/nrniv/neuronapi.cpp index a2a798ff4f..50b6ef839a 100644 --- a/src/nrniv/neuronapi.cpp +++ b/src/nrniv/neuronapi.cpp @@ -39,7 +39,7 @@ struct SymbolTableIterator { extern int nrn_nobanner_; extern int diam_changed; extern int nrn_try_catch_nest_depth; -extern "C" void nrnpy_set_pr_etal(int (*cbpr_stdoe)(int, char*), int (*cbpass)()); +extern "C" void nrnpy_set_pr_etal(int (*cbpr_stdoe)(int, const char*), int (*cbpass)()); int ivocmain_session(int, const char**, const char**, int start_session); void simpleconnectsection(); extern Object* hoc_newobj1(Symbol*, int); @@ -58,7 +58,7 @@ int nrn_init(int argc, const char** argv) { return ivocmain_session(final_argc, final_argv, nullptr, 0); } -void nrn_stdout_redirect(int (*myprint)(int, char*)) { +void nrn_stdout_redirect(int (*myprint)(int, const char*)) { // the first argument of myprint is an integer indicating the output stream // if the int is 1, then stdout, else stderr // the char* is the message to display diff --git a/src/nrniv/neuronapi.h b/src/nrniv/neuronapi.h index 0c39c8c0a9..ed641650af 100644 --- a/src/nrniv/neuronapi.h +++ b/src/nrniv/neuronapi.h @@ -28,7 +28,7 @@ typedef enum { * Initialization ****************************************/ int nrn_init(int argc, const char** argv); -void nrn_stdout_redirect(int (*myprint)(int, char*)); +void nrn_stdout_redirect(int (*myprint)(int, const char*)); /**************************************** * Sections diff --git a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp index 158ae0c028..68e6555511 100644 --- a/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp +++ b/src/nrniv/nrncore_write/callbacks/nrncore_callbacks.cpp @@ -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; diff --git a/src/nrniv/nrncore_write/utils/nrncore_utils.cpp b/src/nrniv/nrncore_write/utils/nrncore_utils.cpp index eae0925cfb..8c5f640b27 100644 --- a/src/nrniv/nrncore_write/utils/nrncore_utils.cpp +++ b/src/nrniv/nrncore_write/utils/nrncore_utils.cpp @@ -105,7 +105,7 @@ void nrnbbcore_register_mapping() { int nlfp = vector_capacity(lfp); if (nsec != nseg) { - Printf("Error: Section and Segment mapping vectors should have same size!\n"); + logger.print("Error: Section and Segment mapping vectors should have same size!\n"); abort(); } diff --git a/src/nrniv/nrnpy.cpp b/src/nrniv/nrnpy.cpp index 9176a63858..a801368a3c 100644 --- a/src/nrniv/nrnpy.cpp +++ b/src/nrniv/nrnpy.cpp @@ -16,6 +16,8 @@ #include #include +#include // for the formatter of std::array + namespace neuron::python { // Declared extern in nrnpy.h, defined here. impl_ptrs methods; @@ -163,9 +165,7 @@ static void set_nrnpylib() { line.remove_prefix(prefix.size()); line.remove_suffix(suffix.size()); if (!glob_var.empty() && glob_var != line) { - Printf(fmt::format( - "WARNING: overriding {} = {} with {}\n", env_var, glob_var, line) - .c_str()); + logger.print("WARNING: overriding {} = {} with {}\n", env_var, glob_var, line); } glob_var = line; } @@ -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,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; @@ -279,18 +273,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; } } @@ -306,15 +295,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/nrniv/vrecord.cpp b/src/nrniv/vrecord.cpp index 131595070c..ff4df1c884 100644 --- a/src/nrniv/vrecord.cpp +++ b/src/nrniv/vrecord.cpp @@ -228,8 +228,7 @@ void VecPlayStep::deliver(double tt, NetCvode* ns) { void VecPlayStep::pr() { - Printf("VecPlayStep "); - Printf("%s.x[%d]\n", hoc_object_name(y_->obj_), current_index_); + logger.print("VecPlayStep {}.x[{}]\n", hoc_object_name(y_->obj_), current_index_); } VecPlayContinuous::VecPlayContinuous(neuron::container::data_handle pd, diff --git a/src/nrnmpi/memory_usage.cpp b/src/nrnmpi/memory_usage.cpp index 084a572939..737681741e 100644 --- a/src/nrnmpi/memory_usage.cpp +++ b/src/nrnmpi/memory_usage.cpp @@ -46,7 +46,7 @@ void nrnmpi_memory_stats(neuron::container::MemoryStats& stats, void nrnmpi_print_memory_stats(neuron::container::MemoryStats const& memory_stats) { if (nrnmpi_myid_world == 0) { - Printf(fmt::format("{}\n", format_memory_usage(memory_stats.total)).c_str()); + logger.print("{}\n", format_memory_usage(memory_stats.total)); } } #endif diff --git a/src/nrnmpi/nrnmpi_dynam.cpp b/src/nrnmpi/nrnmpi_dynam.cpp index 0f8eb4d8f0..74b930a570 100644 --- a/src/nrnmpi/nrnmpi_dynam.cpp +++ b/src/nrnmpi/nrnmpi_dynam.cpp @@ -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 @@ -260,7 +260,7 @@ std::string nrnmpi_load() { void nrnmpi_load_or_exit() { auto const err = nrnmpi_load(); if (!err.empty()) { - Printf(fmt::format("{}\n", err).c_str()); + logger.print("{}\n", err); std::exit(1); } } diff --git a/src/nrnoc/cabcode.cpp b/src/nrnoc/cabcode.cpp index fe6de4e3a2..b047b96bca 100644 --- a/src/nrnoc/cabcode.cpp +++ b/src/nrnoc/cabcode.cpp @@ -92,7 +92,7 @@ void nrn_secstack(int i) { } #if 1 if (isecstack > i) { - Printf("The sectionstack index should be %d but it is %d\n", i, isecstack); + logger.print("The sectionstack index should be {} but it is {}\n", i, isecstack); hoc_warning( "prior to version 5.3 the section stack would not have been properly popped\n\ and the currently accessed section would have been ", @@ -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); } diff --git a/src/nrnoc/clamp.cpp b/src/nrnoc/clamp.cpp index 8d7f908b13..6637e6a8c8 100644 --- a/src/nrnoc/clamp.cpp +++ b/src/nrnoc/clamp.cpp @@ -49,24 +49,24 @@ void print_clamp() { if (maxlevel == 0) return; #ifndef _OMPSS_ - Printf( - "%s fclamp(%d, %g) /* Second arg is location */\n\ -/* fclamp( #, duration(ms), magnitude(mV)) ; clamp_resist = %g */\n", + logger.print( + "{} fclamp({}, {}) /* Second arg is location */\n" + "/* fclamp( #, duration(ms), magnitude(mV)) ; clamp_resist = {} */\n", secname(sec), maxlevel, loc, clamp_resist); #else - Printf( - "%s fclamp(%d, %g) /* Second arg is location */\nfclamp( #, duration(ms), magnitude(mV)) ; " - "clamp_resist = %g */\n", + logger.print( + "{} fclamp({}, {}) /* Second arg is location */\nfclamp( #, duration(ms), magnitude(mV)) ; " + "clamp_resist = {} */\n", secname(sec), maxlevel, loc, clamp_resist); #endif for (i = 0; i < maxlevel; i++) { - Printf(" fclamp(%2d,%13g,%14g)\n", i, duration[i], vc[i]); + logger.print(" fclamp({:2d},{:13g},{:14g})\n", i, duration[i], vc[i]); } } diff --git a/src/nrnoc/eion.cpp b/src/nrnoc/eion.cpp index 6dece3efb8..9cc43b1b2f 100644 --- a/src/nrnoc/eion.cpp +++ b/src/nrnoc/eion.cpp @@ -266,10 +266,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); } } diff --git a/src/nrnoc/fadvance.cpp b/src/nrnoc/fadvance.cpp index a8a06f314e..b1b90e0c48 100644 --- a/src/nrnoc/fadvance.cpp +++ b/src/nrnoc/fadvance.cpp @@ -95,12 +95,12 @@ double nrn_ndt_, nrn_tbase_, nrn_dt_; void nrn_chk_ndt() { if (dt != nrn_dt_ || t != nrn_tbase_ + nrn_ndt_ * nrn_dt_) { if (nrnmpi_myid == 0) - Printf("nrn_chk_ndt t=%g dt=%g old nrn_tbase_=%g nrn_ndt_=%g nrn_dt_=%g\n", - t, - dt, - nrn_tbase_, - nrn_ndt_, - nrn_dt_); + logger.print("nrn_chk_ndt t={} dt={} old nrn_tbase_={} nrn_ndt_={} nrn_dt_={}\n", + t, + dt, + nrn_tbase_, + nrn_ndt_, + nrn_dt_); nrn_dt_ = dt; nrn_tbase_ = t; nrn_ndt_ = 0.; @@ -677,31 +677,31 @@ void nrn_print_matrix(NrnThread* _nt) { int i, n = spGetSize(_nt->_sp13mat, 0); spPrint(_nt->_sp13mat, 1, 1, 1); for (i = 1; i <= n; ++i) { - Printf("%d %g\n", i, _nt->actual_rhs(i)); + logger.print("{} {}\n", i, _nt->actual_rhs(i)); } } } else if (_nt) { for (inode = 0; inode < _nt->end; ++inode) { nd = _nt->_v_node[inode]; - Printf("%d %g %g %g %g\n", - inode, - *nrn_classicalNodeB(nd), - *nrn_classicalNodeA(nd), - NODED(nd), - NODERHS(nd)); + logger.print("{} {} {} {} {}\n", + inode, + *nrn_classicalNodeB(nd), + *nrn_classicalNodeA(nd), + NODED(nd), + NODERHS(nd)); } } else { for (isec = 0; isec < section_count; ++isec) { sec = secorder[isec]; for (inode = 0; inode < sec->nnode; ++inode) { nd = sec->pnode[inode]; - Printf("%d %d %g %g %g %g\n", - isec, - inode, - *nrn_classicalNodeB(nd), - *nrn_classicalNodeA(nd), - NODED(nd), - NODERHS(nd)); + logger.print("{} {} {} {} {} {}\n", + isec, + inode, + *nrn_classicalNodeB(nd), + *nrn_classicalNodeA(nd), + NODED(nd), + NODERHS(nd)); } } } diff --git a/src/nrnoc/fstim.cpp b/src/nrnoc/fstim.cpp index c706dfa2a0..7a5960d8d1 100644 --- a/src/nrnoc/fstim.cpp +++ b/src/nrnoc/fstim.cpp @@ -52,16 +52,17 @@ void print_stim() { if (maxstim == 0) return; /*SUPPRESS 440*/ - Printf("fstim(%d)\n/* section fstim( #, loc, delay(ms), duration(ms), magnitude(namp)) */\n", - maxstim); + logger.print( + "fstim({})\n/* section fstim( #, loc, delay(ms), duration(ms), magnitude(namp)) */\n", + maxstim); for (i = 0; i < maxstim; i++) { - Printf("%-15s fstim(%2d,%4g,%10g,%13g,%16g)\n", - secname(pstim[i].sec), - i, - pstim[i].loc, - pstim[i].delay, - pstim[i].duration, - pstim[i].mag); + logger.print("{:-15s} fstim({:2d},{:4g},{:10g},{:13g},{:16g})\n", + secname(pstim[i].sec), + i, + pstim[i].loc, + pstim[i].delay, + pstim[i].duration, + pstim[i].mag); } } diff --git a/src/nrnoc/init.cpp b/src/nrnoc/init.cpp index 267eac5c55..fb46769ad2 100644 --- a/src/nrnoc/init.cpp +++ b/src/nrnoc/init.cpp @@ -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 @@ -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 @@ -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 { diff --git a/src/nrnoc/psection.cpp b/src/nrnoc/psection.cpp index ef5565b2ee..5ef0c2e1f4 100644 --- a/src/nrnoc/psection.cpp +++ b/src/nrnoc/psection.cpp @@ -15,32 +15,32 @@ void psection(void) { verify_structure(); sec = chk_access(); p = sec->prop; - Printf("%s {", secname(sec)); - Printf(" nseg=%d L=%g Ra=%g", sec->nnode - 1, section_length(sec), nrn_ra(sec)); + logger.print("{} {{", secname(sec)); + logger.print(" nseg={} L={} Ra={}", sec->nnode - 1, section_length(sec), nrn_ra(sec)); if (p->dparam[4].get() != 1) { - Printf(" rallbranch=%g", p->dparam[4].get()); + logger.print(" rallbranch={}", p->dparam[4].get()); } - Printf("\n"); + logger.print("\n"); if (sec->parentsec) { - Printf(" %s ", secname(sec->parentsec)); - Printf("connect %s (%g), %g\n", - secname(sec), - p->dparam[3].get(), - p->dparam[1].get()); + logger.print(" {} ", secname(sec->parentsec)); + logger.print("connect {} ({}), {}\n", + secname(sec), + p->dparam[3].get(), + p->dparam[1].get()); } else { v_setup_vectors(); /*SUPPRESS 440*/ - Printf(" /*location %g attached to cell %d*/\n", - p->dparam[3].get(), - sec->parentnode->v_node_index); + logger.print(" /*location {} attached to cell {}*/\n", + p->dparam[3].get(), + sec->parentnode->v_node_index); } if (sec->nnode) { /*SUPPRESS 440*/ - Printf(" /* First segment only */\n"); + logger.print(" /* First segment only */\n"); p1 = sec->pnode[0]->prop; pnode(p1); } - Printf("}\n"); + logger.print("}}\n"); hoc_retpushx(1.); } @@ -53,7 +53,7 @@ static void pnode(Prop* p1) { } pnode(p1->next); /*print in insert order*/ sym = memb_func[p1->_type].sym; - Printf(" insert %s {", sym->name); + logger.print(" insert {} {{", sym->name); if (sym->s_varn) { for (j = 0; j < sym->s_varn; j++) { Symbol* s = sym->u.ppsym[j]; @@ -61,12 +61,12 @@ static void pnode(Prop* p1) { if (p1->ob) { printf(" %s=%g", s->name, p1->ob->u.dataspace[s->u.rng.index].pval[0]); } else { - Printf(" %s=%g", s->name, p1->param_legacy(s->u.rng.index)); + logger.print(" {}={}", s->name, p1->param_legacy(s->u.rng.index)); } } } } - Printf("}\n"); + logger.print("}}\n"); } extern void print_stim(void); diff --git a/src/nrnoc/seclist.cpp b/src/nrnoc/seclist.cpp index 584612113f..1fc9cbf260 100644 --- a/src/nrnoc/seclist.cpp +++ b/src/nrnoc/seclist.cpp @@ -237,7 +237,7 @@ static double printnames(void* v) { List* sl = (List*) v; ITERATE_REMOVE(q, q1, sl) /*{*/ if (q->element.sec->prop) { - Printf("%s\n", secname(q->element.sec)); + logger.print("{}\n", secname(q->element.sec)); } } return 1.; diff --git a/src/nrnoc/secref.cpp b/src/nrnoc/secref.cpp index 7b1f5dd793..0d91dfdbd2 100644 --- a/src/nrnoc/secref.cpp +++ b/src/nrnoc/secref.cpp @@ -101,7 +101,7 @@ static double s_rename(void* v) { sec = (Section*) v; if (!sec->prop) { - Printf("SectionRef[???].sec is a deleted section\n"); + logger.print("SectionRef[???].sec is a deleted section\n"); return 0.; } #if USE_PYTHON @@ -112,7 +112,7 @@ static double s_rename(void* v) { #endif qsec = sec->prop->dparam[8].get(); if (sec->prop->dparam[0].get()) { - Printf("%s must first be unnamed\n", secname(sec)); + logger.print("{} must first be unnamed\n", secname(sec)); return 0.; } @@ -129,7 +129,8 @@ static double s_rename(void* v) { hoc_objectdata = hoc_top_level_data; if (sym) { if (sym->type != SECTION || (sym->arayinfo && sym->arayinfo->nsub > 1)) { - Printf("The new name already exists and is not a SECTION or has a dimension > 1\n"); + logger.print( + "The new name already exists and is not a SECTION or has a dimension > 1\n"); hoc_objectdata = obdsav; return 0; } @@ -138,9 +139,10 @@ static double s_rename(void* v) { pitm = hoc_top_level_data[sym->u.oboff].psecitm; for (i = 0; i < n; ++i) { if (pitm[i]) { - Printf("Previously existing %s[%d] points to a section which is being deleted\n", - sym->name, - i); + logger.print( + "Previously existing {}[{}] points to a section which is being deleted\n", + sym->name, + i); sec_free(pitm[i]); } } @@ -174,12 +176,14 @@ static double s_rename(void* v) { /*assert(is_obj_type(ob, "SectionRef")*/ sec = (Section*) ob->u.this_pointer; if (!sec->prop) { - Printf("%s references a deleted section\n", hoc_object_name(ob)); + logger.print("{} references a deleted section\n", hoc_object_name(ob)); hoc_objectdata = obdsav; return 0; } if (sec->prop->dparam[0].get()) { - Printf("Item %d of second list arg, %s, must first be unnamed\n", i, secname(sec)); + logger.print("Item {} of second list arg, {}, must first be unnamed\n", + i, + secname(sec)); return 0; } qsec = sec->prop->dparam[8].get(); diff --git a/src/nrnoc/solve.cpp b/src/nrnoc/solve.cpp index 38aa3ebc53..68fe8c81b5 100644 --- a/src/nrnoc/solve.cpp +++ b/src/nrnoc/solve.cpp @@ -294,15 +294,15 @@ void nrnhoc_topology(void) /* print the topology of the branched cable */ hoc_Item* q; v_setup_vectors(); - Printf("\n"); + logger.print("\n"); ITERATE(q, section_list) { Section* sec = (Section*) VOIDITM(q); if (sec->parentsec == (Section*) 0) { - Printf("|"); + logger.print("|"); dashes(sec, 0, '-'); } } - Printf("\n"); + logger.print("\n"); hoc_retpushx(1.); } @@ -313,17 +313,17 @@ static void dashes(Section* sec, int offset, int first) { i = (int) nrn_section_orientation(sec); Sprintf(direc, "(%d-%d)", i, 1 - i); for (i = 0; i < offset; i++) - Printf(" "); - Printf("%c", first); + logger.print(" "); + logger.print("{:c}", first); for (i = 2; i < sec->nnode; i++) - Printf("-"); + logger.print("-"); if (sec->prop->dparam[4].get() == 1) { - Printf("| %s%s\n", secname(sec), direc); + logger.print("| {}{}\n", secname(sec), direc); } else { - Printf("| %s%s with %g rall branches\n", - secname(sec), - direc, - sec->prop->dparam[4].get()); + logger.print("| {}{} with {} rall branches\n", + secname(sec), + direc, + sec->prop->dparam[4].get()); } /* navigate the sibling list backwards */ /* note that the sibling list is organized monotonically by @@ -334,7 +334,7 @@ static void dashes(Section* sec, int offset, int first) { while (scnt--) { ch = (Section*) hoc_objpop(); i = node_index_exact(sec, nrn_connection_position(ch)); - Printf(" "); + logger.print(" "); dashes(ch, i + offset + 1, 0140); /* the ` char*/ } } @@ -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 diff --git a/src/nrnoc/synapse.cpp b/src/nrnoc/synapse.cpp index 6ce2f8e9d2..33d9e6b592 100644 --- a/src/nrnoc/synapse.cpp +++ b/src/nrnoc/synapse.cpp @@ -68,17 +68,18 @@ void print_syn(void) { if (maxstim == 0) return; /*SUPPRESS 440*/ - Printf("fsyn(%d)\n/* section fsyn( #, loc, delay(ms), tau(ms), conduct(uS), erev(mV)) */\n", - maxstim); + logger.print( + "fsyn({})\n/* section fsyn( #, loc, delay(ms), tau(ms), conduct(uS), erev(mV)) */\n", + maxstim); for (i = 0; i < maxstim; i++) { - Printf("%-15s fsyn(%2d,%4g,%10g,%8g,%14g,%9g)\n", - secname(pstim[i].sec), - i, - pstim[i].loc, - pstim[i].delay, - pstim[i].duration, - pstim[i].mag, - pstim[i].erev); + logger.print("{:-15s} fsyn({:2d},{:4g},{:10g},{:8g},{:14g},{:9g})\n", + secname(pstim[i].sec), + i, + pstim[i].loc, + pstim[i].delay, + pstim[i].duration, + pstim[i].mag, + pstim[i].erev); } } diff --git a/src/nrnoc/treeset.cpp b/src/nrnoc/treeset.cpp index 2a1c0abf97..22f42bb15c 100644 --- a/src/nrnoc/treeset.cpp +++ b/src/nrnoc/treeset.cpp @@ -1438,7 +1438,8 @@ void nrn_define_shape(void) { continue; } if (fabs(y1) < 1e-6 && fabs(x1) < 1e-6) { - Printf("nrn_define_shape: %s first and last 3-d point at same (x,y)\n", secname(psec)); + logger.print("nrn_define_shape: {} first and last 3-d point at same (x,y)\n", + secname(psec)); angle = 0.; } else { angle = atan2(y1, x1); @@ -2170,7 +2171,7 @@ static void nrn_sort_node_data(neuron::container::Node::storage::frozen_token_ty // objects. In this case we can figure out which the missing entries are and permute them to // the end of the global vectors. auto missing_elements = node_data_size - global_i; - Printf(fmt::format("permuting {} 'lost' Nodes to the end\n", missing_elements).c_str()); + logger.print("permuting {} 'lost' Nodes to the end\n", missing_elements); // There are `missing_elements` integers from the range [0 .. node_data_size-1] whose values // in `node_data_permutation` are still std::numeric_limits::max(). for (auto global_row = 0ul; global_row < node_data_size; ++global_row) { diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index b6eb51a9b9..eda363e3de 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -436,7 +436,7 @@ int hocobj_pushargs(PyObject* args, std::vector& s2free) { Py2NRNString str(po, /* disable_release */ true); if (str.err()) { // Since Python error has been set, need to clear, or hoc_execerror - // printing with Printf will generate a + // printing with logger.print will generate a // Exception ignored on calling ctypes callback function. // So get the message, clear, and make the message // part of the execerror. @@ -454,7 +454,7 @@ int hocobj_pushargs(PyObject* args, std::vector& s2free) { // the object which can raise an error for nrn.Section, nrn.Segment, // etc. if the internal Section is invalid (Section.prop == NULL). // That, in consequence, will generate an - // Exception ignored on calling ctypes callback function: name); } @@ -374,7 +374,7 @@ static double praxis_efun(Object* ho, Object* v) { if (!r) { char* mes = nrnpyerr_str(); if (mes) { - Fprintf(stderr, "%s\n", mes); + logger.error("{}\n", mes); free(mes); hoc_execerror("Call of Python Callable failed in praxis_efun", NULL); } @@ -424,7 +424,7 @@ static int hoccommand_exec_strret(Object* ho, char* buf, int size) { } else { char* mes = nrnpyerr_str(); if (mes) { - Fprintf(stderr, "%s\n", mes); + logger.error("{}\n", mes); free(mes); hoc_execerror("Python Callback failed", 0); } @@ -448,7 +448,7 @@ static void grphcmdtool(Object* ho, int type, double x, double y, int key) { if (!r) { char* mes = nrnpyerr_str(); if (mes) { - Fprintf(stderr, "%s\n", mes); + logger.error("{}\n", mes); free(mes); hoc_execerror("Python Callback failed", 0); } @@ -518,7 +518,7 @@ static double func_call(Object* ho, int narg, int* err) { if (!err || *err) { char* mes = nrnpyerr_str(); if (mes) { - Fprintf(stderr, "%s\n", mes); + logger.error("{}\n", mes); free(mes); } if (PyErr_Occurred()) { @@ -686,18 +686,18 @@ static char* nrnpyerr_str() { if (py_str) { Py2NRNString mes(py_str); if (mes.err()) { - Fprintf(stderr, "nrnperr_str: Py2NRNString failed\n"); + logger.error("nrnperr_str: Py2NRNString failed\n"); } else { cmes = strdup(mes.c_str()); if (!cmes) { - Fprintf(stderr, "nrnpyerr_str: strdup failed\n"); + logger.error("nrnpyerr_str: strdup failed\n"); } } } if (!py_str) { PyErr_Print(); - Fprintf(stderr, "nrnpyerr_str failed\n"); + logger.error("nrnpyerr_str failed\n"); } Py_XDECREF(module_name); @@ -732,7 +732,7 @@ std::vector call_picklef(const std::vector& fname, int narg) { if (!result) { char* mes = nrnpyerr_str(); if (mes) { - Fprintf(stderr, fmt::format("{}\n", mes).c_str()); + logger.error("{}\n", mes); free(mes); hoc_execerror("PyObject method call failed:", NULL); } diff --git a/src/nrnpython/nrnpython.cpp b/src/nrnpython/nrnpython.cpp index 41fb8c4c30..1833f020af 100644 --- a/src/nrnpython/nrnpython.cpp +++ b/src/nrnpython/nrnpython.cpp @@ -124,7 +124,7 @@ int nrnpy_pyrun(const char* fname) { if (fp) { nrnpython_set_path(fname); } else { - Fprintf(stderr, fmt::format("Could not open {}\n", fname).c_str()); + logger.error("Could not open {}\n", fname); return 0; } fclose(fp); diff --git a/src/oc/axis.cpp b/src/oc/axis.cpp index eeceaf2680..541f4582bc 100644 --- a/src/oc/axis.cpp +++ b/src/oc/axis.cpp @@ -252,9 +252,9 @@ void hoc_Plot(void) { return; } } else { - Printf("plot(mode)\nplot(x, y)\nplot(mode, x, y\n"); - Printf("axis()\naxis(clip)\naxis(xorg, xsize, yorg, ysize)\n"); - Printf("axis(xstart, xstop, ntic, ystart, ystop, ntic)\n"); + logger.print("plot(mode)\nplot(x, y)\nplot(mode, x, y\n"); + logger.print("axis()\naxis(clip)\naxis(xorg, xsize, yorg, ysize)\n"); + logger.print("axis(xstart, xstop, ntic, ystart, ystop, ntic)\n"); Ret(1.); return; } diff --git a/src/oc/code.cpp b/src/oc/code.cpp index d112fb7bb3..e49cee0bc0 100644 --- a/src/oc/code.cpp +++ b/src/oc/code.cpp @@ -457,7 +457,7 @@ void hoc_prstack() { stkp); ++i; } - Printf(oss.str().c_str()); + logger.print("{}", oss.str()); } void hoc_on_init_register(Pfrv pf) { @@ -1340,37 +1340,35 @@ void frame_debug() { } for (i = 5, f = fp; f != frame && --i; f = f - 1) { /* print only to depth of 5 */ for (j = i; j; j--) { - Fprintf(stderr, " "); + logger.error(" "); } if (f->ob) { - Fprintf(stderr, "%s%s.%s(", id, hoc_object_name(f->ob), f->sp->name); // error + logger.error("{}{}.{}(", id, hoc_object_name(f->ob), f->sp->name); // error } else { - Fprintf(stderr, "%s%s(", id, f->sp->name); + logger.error("{}{}(", id, f->sp->name); } for (j = 1; j <= f->nargs;) { auto const& entry = f->argn[j - f->nargs]; - std::visit(overloaded{[](double val) { Fprintf(stderr, "%g", val); }, + std::visit(overloaded{[](double val) { logger.error("{}", val); }, [](char** pstr) { const char* s = *pstr; if (strlen(s) > 15) { - Fprintf(stderr, "\"%.10s...\"", s); + logger.error("\"{:.10s}...\"", s); } else { - Fprintf(stderr, "\"%s\"", s); + logger.error("\"{}\"", s); } }, - [](Object** pobj) { - Fprintf(stderr, "%s", hoc_object_name(*pobj)); - }, - [](auto const&) { Fprintf(stderr, "..."); }}, + [](Object** pobj) { logger.error("{}", hoc_object_name(*pobj)); }, + [](auto const&) { logger.error("..."); }}, entry); if (++j <= f->nargs) { - Fprintf(stderr, ", "); + logger.error(", "); } } - Fprintf(stderr, ")\n"); + logger.error(")\n"); } if (i <= 0) { - Fprintf(stderr, "and others\n"); + logger.error("and others\n"); } } @@ -2371,9 +2369,9 @@ int hoc_araypt(Symbol* sp, int type) { // pop top value from stack, print it void hoc_print() { - Printf("\t"); + logger.print("\t"); hoc_prexpr(); - Printf("\n"); + logger.print("\n"); } // print numeric value diff --git a/src/oc/code2.cpp b/src/oc/code2.cpp index 679c396cdb..f741aee005 100644 --- a/src/oc/code2.cpp +++ b/src/oc/code2.cpp @@ -534,59 +534,59 @@ static void symdebug(const char* s, Symlist* list) /* for debugging display the { Symbol* sp; - Printf("\n\nSymbol list %s\n\n", s); + logger.print("\n\nSymbol list {}\n\n", s); if (list) for (sp = list->first; sp != (Symbol*) 0; sp = sp->next) { - Printf("name:%s\ntype:", sp->name); + logger.print("name:{}\ntype:", sp->name); switch (sp->type) { case VAR: if (!is_array(*sp)) { if (sp->subtype == USERINT) - Printf("VAR USERINT %8d", *(sp->u.pvalint)); + logger.print("VAR USERINT {:8d}", *(sp->u.pvalint)); else if (sp->subtype == USERDOUBLE) - Printf("VAR USERDOUBLE %.8g", *(OPVAL(sp))); + logger.print("VAR USERDOUBLE {:.8g}", *(OPVAL(sp))); else - Printf("VAR %.8g", *(OPVAL(sp))); + logger.print("VAR {:.8g}", *(OPVAL(sp))); } else { if (sp->subtype == USERINT) - Printf("ARRAY USERINT"); + logger.print("ARRAY USERINT"); else if (sp->subtype == USERDOUBLE) - Printf("ARRAY USERDOUBLE"); + logger.print("ARRAY USERDOUBLE"); else - Printf("ARRAY"); + logger.print("ARRAY"); } break; case NUMBER: - Printf("NUMBER %.8g", *(OPVAL(sp))); + logger.print("NUMBER {:.8g}", *(OPVAL(sp))); break; case STRING: - Printf("STRING %s", *(OPSTR(sp))); + logger.print("STRING {}", *(OPSTR(sp))); break; case UNDEF: - Printf("UNDEF"); + logger.print("UNDEF"); break; case BLTIN: - Printf("BLTIN"); + logger.print("BLTIN"); break; case AUTO: - Printf("AUTO"); + logger.print("AUTO"); break; case FUNCTION: - Printf("FUNCTION"); + logger.print("FUNCTION"); symdebug(sp->name, sp->u.u_proc->list); break; case PROCEDURE: - Printf("PROCEDURE"); + logger.print("PROCEDURE"); symdebug(sp->name, sp->u.u_proc->list); break; case FUN_BLTIN: - Printf("FUN_BLTIN"); + logger.print("FUN_BLTIN"); break; default: - Printf("%d", sp->type); + logger.print("{}", sp->type); break; } - Printf("\n"); + logger.print("\n"); } } @@ -597,15 +597,15 @@ void hoc_symbols(void) /* display the types above */ if (hoc_zzdebug == 0) for (i = 0; type_sym[i].t_type != 0; i++) { - Printf("\n%s\n", type_sym[i].name); + logger.print("\n{}\n", type_sym[i].name); for (sp = hoc_symlist->first; sp != (Symbol*) 0; sp = sp->next) if (sp->type == type_sym[i].t_type) { - Printf("\t%s", sp->name); + logger.print("\t{}", sp->name); switch (sp->type) { case VAR: if (is_array(*sp)) { for (j = 0; j < sp->arayinfo->nsub; j++) - Printf("[%d]", sp->arayinfo->sub[j]); + logger.print("[{}]", sp->arayinfo->sub[j]); } break; @@ -613,7 +613,7 @@ void hoc_symbols(void) /* display the types above */ break; } } - Printf("\n"); + logger.print("\n"); } else { symdebug("p_symlist", hoc_p_symlist); diff --git a/src/oc/debug.cpp b/src/oc/debug.cpp index 2f8aeb5626..0545e57bfd 100644 --- a/src/oc/debug.cpp +++ b/src/oc/debug.cpp @@ -9,7 +9,8 @@ int hoc_zzdebug; -#define prcod(c1, c2) else if (p->pf == c1) Printf("%p %p %s", fmt::ptr(p), fmt::ptr(p->pf), c2) +#define prcod(c1, c2) \ + else if (p->pf == c1) logger.print("{} {} {}", fmt::ptr(p), fmt::ptr(p->pf), c2) void hoc_debug(void) /* print the machine */ { @@ -24,7 +25,7 @@ void debugzz(Inst* p) { #if !OCSMALL { if (p->in == STOP) - Printf("STOP\n"); + logger.print("STOP\n"); prcod(hoc_nopop, "POP\n"); prcod(hoc_eval, "EVAL\n"); prcod(hoc_add, "ADD\n"); @@ -124,20 +125,20 @@ void debugzz(Inst* p) { else { size_t offset = (size_t) p->in; if (offset < 1000) - Printf("relative %d\n", p->i); + logger.print("relative {}\n", p->i); else { offset = (size_t) (p->in) - (size_t) p; if (offset > (size_t) hoc_prog - (size_t) p && offset < (size_t) (&hoc_prog[2000]) - (size_t) p) - Printf("relative %ld\n", p->in - p); + logger.print("relative {}\n", p->in - p); else if (p->sym->name != (char*) 0) { if (p->sym->name[0] == '\0') { - Printf("constant or string pointer\n"); - /*Printf("value=%g\n", p->sym->u.val);*/ + logger.print("constant or string pointer\n"); + /*logger.print("value={}\n", p->sym->u.val);*/ } else - Printf("%s\n", p->sym->name); + logger.print("{}\n", p->sym->name); } else - Printf("symbol without name\n"); + logger.print("symbol without name\n"); } } p++; diff --git a/src/oc/fileio.cpp b/src/oc/fileio.cpp index 140b53eed0..f4cb1052d7 100644 --- a/src/oc/fileio.cpp +++ b/src/oc/fileio.cpp @@ -15,6 +15,8 @@ #include #include "nrnfilewrap.h" +#include "utils/logger.hpp" + extern char* neuron_home; NrnFILEWrap* hoc_frin; @@ -750,11 +752,11 @@ void hoc_Chdir(void) { } int nrn_is_python_extension; -int (*nrnpy_pr_stdoe_callback)(int, char*); +Logger logger; static int (*nrnpy_pass_callback)(); -extern "C" void nrnpy_set_pr_etal(int (*cbpr_stdoe)(int, char*), int (*cbpass)()) { - nrnpy_pr_stdoe_callback = cbpr_stdoe; +extern "C" void nrnpy_set_pr_etal(int (*cbpr_stdoe)(int, const char*), int (*cbpass)()) { + logger.setCallback(cbpr_stdoe); nrnpy_pass_callback = cbpass; } diff --git a/src/oc/hoc.cpp b/src/oc/hoc.cpp index 6eded05477..27a3cdbf29 100644 --- a/src/oc/hoc.cpp +++ b/src/oc/hoc.cpp @@ -519,7 +519,7 @@ void hoc_arayinstal(void) /* allocate storage for arrays */ i = hoc_arayinfo_install(sp, nsub); if ((OPVAL(sp) = (double*) hoc_Ecalloc((unsigned) i, sizeof(double))) == (double*) 0) { hoc_freearay(sp); - Fprintf(stderr, "Not enough space for array %s\n", sp->name); + logger.error("Not enough space for array {}\n", sp->name); hoc_malchk(); hoc_execerror("", (char*) 0); } @@ -700,7 +700,7 @@ void print_bt() { size = backtrace(frames, nframes); // print out all the frames to stderr - Fprintf(stderr, "Backtrace:\n"); + logger.error("Backtrace:\n"); // get the stacktrace as an array of strings bt_strings = backtrace_symbols(frames, size); if (bt_strings) { @@ -712,12 +712,12 @@ void print_bt() { if (status) { status = cxx_demangle(symbol, &funcname, &funcname_size); if (status == 0) { // demangling worked - Fprintf(stderr, "\t%s : %s+%s\n", bt_strings[i], funcname, offset); + logger.error("\t{} : {}+{}\n", bt_strings[i], funcname, offset); } else { // demangling failed, fallback - Fprintf(stderr, "\t%s : %s()+%s\n", bt_strings[i], symbol, offset); + logger.error("\t{} : {}()+{}\n", bt_strings[i], symbol, offset); } } else { // could not parse, simply print the stackframe as is - Fprintf(stderr, "\t%s\n", bt_strings[i]); + logger.error("\t{}\n", bt_strings[i]); } } free(bt_strings); @@ -726,7 +726,7 @@ void print_bt() { free(offset); free(symbol); #else - Fprintf(stderr, "No backtrace info available.\n"); + logger.error("No backtrace info available.\n"); #endif #endif } @@ -737,7 +737,7 @@ void fpecatch(int /* sig */) /* catch floating point exceptions */ #if NRN_FLOAT_EXCEPTION matherr1(); #endif - Fprintf(stderr, "Floating point exception\n"); + logger.error("Floating point exception\n"); print_bt(); if (coredump) { abort(); @@ -749,7 +749,7 @@ void fpecatch(int /* sig */) /* catch floating point exceptions */ __attribute__((noreturn)) void sigsegvcatch(int /* sig */) /* segmentation violation probably due to arg type error */ { - Fprintf(stderr, "Segmentation violation\n"); + logger.error("Segmentation violation\n"); print_bt(); /*ARGSUSED*/ if (coredump) { @@ -760,7 +760,7 @@ __attribute__((noreturn)) void sigsegvcatch(int /* sig */) /* segmentation viola #if HAVE_SIGBUS __attribute__((noreturn)) void sigbuscatch(int /* sig */) { - Fprintf(stderr, "Bus error\n"); + logger.error("Bus error\n"); print_bt(); /*ARGSUSED*/ if (coredump) { @@ -816,9 +816,9 @@ void hoc_main1_init(const char* pname, const char** envp) { hoc_frin = nrn_fw_set_stdin(); hoc_fout = stdout; if (!nrn_is_cable()) { - Fprintf(stderr, "OC INTERPRETER %s %s\n", RCS_hoc_version, RCS_hoc_date); - Fprintf(stderr, - "Copyright 1992 - Michael Hines, Neurobiology Dept., DUMC, Durham, NC. 27710\n"); + logger.error("OC INTERPRETER {} {}\n", RCS_hoc_version, RCS_hoc_date); + logger.error( + "Copyright 1992 - Michael Hines, Neurobiology Dept., DUMC, Durham, NC. 27710\n"); } progname = pname; hoc_init(); @@ -915,7 +915,7 @@ int hoc_main1(int argc, const char** argv, const char** envp) { } return exit_status; } catch (std::exception const& e) { - Fprintf(stderr, fmt::format("hoc_main1 caught exception: {}\n", e.what()).c_str()); + logger.error("hoc_main1 caught exception: {}\n", e.what()); nrn_exit(1); } } @@ -1128,7 +1128,7 @@ int hoc_moreinput() { } return hoc_moreinput(); } else if ((hoc_fin = nrn_fw_fopen(infile, "r")) == (NrnFILEWrap*) 0) { - Fprintf(stderr, "%d %s: can't open %s\n", nrnmpi_myid_world, progname, infile); + logger.error("{} {}: can't open {}\n", nrnmpi_myid_world, progname, infile); #if NRNMPI if (nrnmpi_numprocs_world > 1) { nrnmpi_abort(-1); @@ -1237,12 +1237,12 @@ static int hoc_run1() { } } catch (std::exception const& e) { hoc_fin = sav_fin; - Fprintf(stderr, "hoc_run1: caught exception"); + logger.error("hoc_run1: caught exception"); std::string_view what{e.what()}; if (!what.empty()) { - Fprintf(stderr, fmt::format(": {}", what).c_str()); + logger.error(": {}", what); } - Fprintf(stderr, "\n"); + logger.error("\n"); // Exit if we're not in interactive mode if (!nrn_fw_eq(hoc_fin, stdin)) { return EXIT_FAILURE; @@ -1367,32 +1367,31 @@ void hoc_warning(const char* s, const char* t) /* print warning message */ id[0] = '\0'; } if (t) { - Fprintf(stderr, "%s%s: %s %s\n", id, progname, s, t); + logger.error("{}{}: {} {}\n", id, progname, s, t); } else { - Fprintf(stderr, "%s%s: %s\n", id, progname, s); + logger.error("{}{}: {}\n", id, progname, s); } if (hoc_xopen_file_ && hoc_xopen_file_[0]) { - Fprintf(stderr, "%s in %s near line %d\n", id, hoc_xopen_file_, hoc_lineno); + logger.error("{} in {} near line {}\n", id, hoc_xopen_file_, hoc_lineno); } else { - Fprintf(stderr, "%s near line %d\n", id, hoc_lineno); + logger.error("{} near line {}\n", id, hoc_lineno); } n = strlen(hoc_cbuf); for (cp = hoc_cbuf; cp < (hoc_cbuf + n); ++cp) { if (!isprint((int) (*cp)) && !isspace((int) (*cp))) { - Fprintf(stderr, - "%scharacter \\%03o at position %ld is not printable\n", - id, - ((int) (*cp) & 0xff), - cp - hoc_cbuf); + logger.error("{}character \\{:03o} at position {} is not printable\n", + id, + ((int) (*cp) & 0xff), + cp - hoc_cbuf); break; } } - Fprintf(stderr, "%s %s", id, hoc_cbuf); + logger.error("{} {}", id, hoc_cbuf); if (nrnmpi_numprocs_world > 0) { for (cp = hoc_cbuf; cp != hoc_ctp; cp++) { - Fprintf(stderr, " "); + logger.error(" "); } - Fprintf(stderr, "^\n"); + logger.error("^\n"); } hoc_ctp = hoc_cbuf; *hoc_ctp = '\0'; diff --git a/src/oc/hoc_oop.cpp b/src/oc/hoc_oop.cpp index ce2a68b531..bd3ed717c1 100644 --- a/src/oc/hoc_oop.cpp +++ b/src/oc/hoc_oop.cpp @@ -157,7 +157,7 @@ void hoc_obvar_declare(Symbol* sym, int type, int pmes) { int b = 0; b = (hoc_fin == stdin); if (nrnmpi_myid_world == 0 && (hoc_print_first_instance && b)) { - Printf("first instance of %s\n", sym->name); + logger.print("first instance of {}\n", sym->name); } sym->defined_on_the_fly = 1; } @@ -1059,7 +1059,7 @@ void hoc_object_component() { auto err = fmt::format("'{}' not a public member of '{}'", sym0->name, obp->ctemplate->sym->name); - Fprintf(stderr, fmt::format("{}\n", err).c_str()); + logger.error("{}\n", err); hoc_execerror(err.c_str(), nullptr); } *ptid = obp->ctemplate->id; @@ -2036,9 +2036,9 @@ void hoc_allobjects1(Symlist* sl, int nspace) { ITERATE(q, t->olist) { o = OBJ(q); for (i = 0; i < nspace; ++i) { - Printf(" "); + logger.print(" "); } - Printf("%s with %d refs\n", hoc_object_name(o), o->refcount); + logger.print("{} with {} refs\n", hoc_object_name(o), o->refcount); } hoc_allobjects1(t->symtable, nspace + 1); } @@ -2055,9 +2055,9 @@ void hoc_allobjects2(Symbol* s, int nspace) { ITERATE(q, t->olist) { o = OBJ(q); for (i = 0; i < nspace; ++i) { - Printf(" "); + logger.print(" "); } - Printf("%s with %d refs\n", hoc_object_name(o), o->refcount); + logger.print("{} with {} refs\n", hoc_object_name(o), o->refcount); } } } @@ -2084,16 +2084,16 @@ static void hoc_list_allobjref(Symlist* sl, Objectdata* data, int depth) { for (i = 0; i < total; i++) { obp = data[s->u.oboff].pobj + i; for (id = 0; id < depth; id++) { - Printf(" "); + logger.print(" "); } if (*obp) { - Printf("obp %s[%d] -> %s with %d refs.\n", - s->name, - i, - hoc_object_name(*obp), - (*obp)->refcount); + logger.print("obp {}[{}] -> {} with {} refs.\n", + s->name, + i, + hoc_object_name(*obp), + (*obp)->refcount); } else { - Printf("obp %s[%d] -> NULL\n", s->name, i); + logger.print("obp {}[{}] -> NULL\n", s->name, i); } if (*obp && !(*obp)->recurse && s->subtype != CPLUSOBJECT && (*obp)->u.dataspace != data /* not this */ diff --git a/src/oc/parse.ypp b/src/oc/parse.ypp index 9a6a8a6d36..aab161a8fb 100755 --- a/src/oc/parse.ypp +++ b/src/oc/parse.ypp @@ -639,9 +639,9 @@ stmtlist: /* nothing */ prog_error = $$; if (hoc_fin && nrn_fw_eq(hoc_fin, stdin) && !hoc_pipeflag) { int i; - Printf(">"); + logger.print(">"); for (i = 0; i < ntab; i++) - Printf(" "); + logger.print(" "); } } | stmtlist stmt diff --git a/src/oc/plot.cpp b/src/oc/plot.cpp index 8ded28119a..e97f31481e 100644 --- a/src/oc/plot.cpp +++ b/src/oc/plot.cpp @@ -116,7 +116,7 @@ void hoc_plprint(const char* s) { #endif } else if (!text) { - Printf("%s", s); + logger.print("{}", s); } if (hardplot && hpdev && text && strlen(s)) { hard_text_preamble(); diff --git a/src/oc/symbol.cpp b/src/oc/symbol.cpp index e606dc6cb0..16abbc9fa6 100644 --- a/src/oc/symbol.cpp +++ b/src/oc/symbol.cpp @@ -38,10 +38,10 @@ Symlist* hoc_p_symlist = nullptr; /* current proc, func, or temp table */ /* appropriate times prevents storage leakage. */ void print_symlist(const char* s, Symlist* tab) { - Printf("%s\n", s); + logger.print("{}\n", s); if (tab) for (Symbol* sp = tab->first; sp != nullptr; sp = sp->next) { - Printf("%s %p\n", sp->name, fmt::ptr(sp)); + logger.print("{} {}\n", sp->name, fmt::ptr(sp)); } } @@ -222,10 +222,9 @@ void hoc_free_symspace(Symbol* s1) { /* frees symbol space. Marks it UNDEF */ case VARALIAS: break; default: - Fprintf(stderr, - "In free_symspace may not free all of %s of type=%d\n", - s1->name, - s1->type); + logger.error("In free_symspace may not free all of {} of type={}\n", + s1->name, + s1->type); } if (s1->arayinfo != nullptr) { hoc_free_arrayinfo(s1->arayinfo); diff --git a/src/parallel/bbssrv2mpi.cpp b/src/parallel/bbssrv2mpi.cpp index 1d2d4b6822..c928a4385e 100644 --- a/src/parallel/bbssrv2mpi.cpp +++ b/src/parallel/bbssrv2mpi.cpp @@ -7,7 +7,7 @@ #include "bbssrv2mpi.h" #include "bbssrv.h" #include "bbsimpl.h" -#include "hocdec.h" //Printf +#include "hocdec.h" //logger.print #include "utils/logger.hpp" @@ -246,7 +246,7 @@ void BBSDirectServer::context(bbsmpibuf* send) { handle(); } if (remaining_context_cnt_ > 0) { - Printf("some workers did not receive previous context\n"); + logger.print("some workers did not receive previous context\n"); send_context_->erase(send_context_->begin(), send_context_->end()); nrnmpi_unref(context_buf_); context_buf_ = nullptr; diff --git a/src/utils/logger.hpp b/src/utils/logger.hpp index 9a10e182c6..43735f16be 100644 --- a/src/utils/logger.hpp +++ b/src/utils/logger.hpp @@ -1,25 +1,61 @@ #pragma once -#include +#include +#include -extern int (*nrnpy_pr_stdoe_callback)(int, char*); +#include -template -int Fprintf(FILE* stream, const char* fmt, Args... args) { - if (nrnpy_pr_stdoe_callback && (stream == stdout || stream == stderr)) { - std::string message = fmt::sprintf(fmt, std::forward(args)...); - nrnpy_pr_stdoe_callback(stream == stdout ? 1 : 2, message.data()); - return message.size(); +class Logger { + public: + void setCallback(std::function cb) { + callback = std::move(cb); } - return fmt::fprintf(stream, fmt, args...); -} -template -int Printf(const char* fmt, Args... args) { - if (nrnpy_pr_stdoe_callback) { - std::string message = fmt::sprintf(fmt, std::forward(args)...); - nrnpy_pr_stdoe_callback(1, message.data()); - return message.size(); + const std::function& getCallback() const { + return callback; } - return fmt::printf(fmt, args...); -} + + // Unconditionnaly print non depending of the level + template + void print(std::string_view fmt, Args&&... args) const { + output(1, fmt, std::forward(args)...); + } + + template + void debug(std::string_view fmt, Args&&... args) const { + output(1, fmt, std::forward(args)...); + } + + template + void info(std::string_view fmt, Args&&... args) const { + output(1, fmt, std::forward(args)...); + } + + template + void warning(std::string_view fmt, Args&&... args) const { + output(1, fmt, std::forward(args)...); + } + + template + void error(std::string_view fmt, Args&&... args) const { + output(2, fmt, std::forward(args)...); + } + + template + void output(int out, std::string_view fmt, Args&&... args) const { + std::string message = fmt::format(fmt, std::forward(args)...); + callback(out, message.c_str()); + } + + private: + std::function callback = [](int out, const char* mess) { + if (out == 1) { + std::cout << mess; + } else { + std::cerr << mess; + } + return 0; + }; +}; + +extern Logger logger;