Skip to content

Commit

Permalink
Make PyLog behave consistently with C++ version
Browse files Browse the repository at this point in the history
  • Loading branch information
dvicini committed Sep 12, 2024
1 parent df9b639 commit 14fcd90
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/core/python/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

/// Submit a log message to the Mitusba logging system and tag it with the Python caller
static void PyLog(mitsuba::LogLevel level, const std::string &msg) {

// Do not log if no logger is available. This is consistent with the
// C++-side "Log" function in logger.h.
if (!Thread::thread()->logger())
return;

#if PY_VERSION_HEX >= 0x03090000
PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
PyCodeObject *f_code = PyFrame_GetCode(frame);
Expand All @@ -29,18 +35,6 @@ static void PyLog(mitsuba::LogLevel level, const std::string &msg) {
if (!name.empty() && name[0] != '<')
fmt.insert(2, "()");

if (!Thread::thread()->logger()) {
Throw("No Logger instance is set on the current thread! This is likely due to Log being "
"called from a non-Mitsuba thread. You can manually set a thread's ThreadEnvironment "
"(which includes the logger) using ScopedSetThreadEnvironment e.g.\n"
"# Main thread\n"
"env = mi.ThreadEnvironment()\n"
"# Secondary thread\n"
"with mi.ScopedSetThreadEnvironment(env):\n"
" mi.set_log_level(mi.LogLevel.Info)\n"
" mi.Log(mi.LogLevel.Info, 'Message')\n");
}

Thread::thread()->logger()->log(
level, nullptr /* class_ */,
filename.c_str(), lineno,
Expand Down

0 comments on commit 14fcd90

Please sign in to comment.