Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions python/remage/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,23 @@ def setup_log() -> logging.Logger:
logger.setLevel(logging.DEBUG)
logger.propagate = False

if supports_color():
fmt = "%(log_color)s[%(levelname)-7s ->%(reset)s %(message)s"
# Avoid adding duplicate handlers if setup_log() is called multiple times.
if not any(getattr(h, "_remage_default_handler", False) for h in logger.handlers):
# Keep the visible formatting identical between colored and non-colored output.
plain_fmt = "[%(levelname)-7s -> %(message)s"
colored_fmt = "%(log_color)s[%(levelname)-7s ->%(reset)s %(message)s"

if supports_color():
handler = colorlog.StreamHandler()
handler.setFormatter(
colorlog.ColoredFormatter(colored_fmt, log_colors=LEVEL_COLORS)
)
else:
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter(plain_fmt))

handler = colorlog.StreamHandler()
handler.setFormatter(colorlog.ColoredFormatter(fmt, log_colors=LEVEL_COLORS))
handler.setLevel(logging.DEBUG)
handler._remage_default_handler = True # type: ignore[attr-defined]
logger.addHandler(handler)

set_logging_level(logger, "Summary")
Expand All @@ -96,7 +107,7 @@ def supports_color() -> bool:
"vt100",
"xterm",
]
return sys.stderr.isatty() and any(term in t for t in terms)
return sys.stderr.isatty() and term is not None and any(t in term for t in terms)


def set_logging_level(logger, rmg_log_level):
Expand Down
11 changes: 8 additions & 3 deletions src/RMGManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void RMGManager::SetRandEngineSeed(int seed) {
);
CLHEP::HepRandom::setTheSeed(0);
} else CLHEP::HepRandom::setTheSeed(seed);
RMGLog::Out(RMGLog::summary, "CLHEP::HepRandom seed set to: ", seed);
RMGLog::Out(RMGLog::summary, "CLHEP::HepRandom seed changed to: ", seed, " (user value)");

fIsRandControlled = true;
}
Expand All @@ -341,7 +341,12 @@ void RMGManager::SetRandEngineInternalSeed(int index) {

int array_index = index % 2;
CLHEP::HepRandom::setTheSeed(seeds[array_index]);
RMGLog::Out(RMGLog::summary, "CLHEP::HepRandom seed set to: ", seeds[array_index]);
RMGLog::Out(
RMGLog::summary,
"CLHEP::HepRandom seed changed to: ",
seeds[array_index],
" (from the internal seed table)"
);

fIsRandControlled = true;
}
Expand All @@ -351,7 +356,7 @@ void RMGManager::SetRandSystemEntropySeed() {
std::random_device rd; // uses RDRND or /dev/urandom
auto rand_seed = dist(rd);
CLHEP::HepRandom::setTheSeed(rand_seed);
RMGLog::Out(RMGLog::summary, "CLHEP::HepRandom seed set to: ", rand_seed);
RMGLog::Out(RMGLog::summary, "CLHEP::HepRandom seed changed to: ", rand_seed, " (from system entropy)");
}

void RMGManager::DefineCommands() {
Expand Down
2 changes: 1 addition & 1 deletion src/RMGRunAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ void RMGRunAction::PostprocessOutputFile() const {

try {
fs::rename(worker_tmp, worker_lh5);
RMGLog::Out(RMGLog::summary, "Moved output file ", worker_tmp.string(), " to ", worker_lh5.string());
RMGLog::Out(RMGLog::detail, "Moved output file ", worker_tmp.string(), " to ", worker_lh5.string());
} catch (const fs::filesystem_error& e) {
RMGLog::Out(
RMGLog::error,
Expand Down
2 changes: 1 addition & 1 deletion tests/basics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ add_test(NAME basics/rand-seed
COMMAND ${REMAGE_PYEXE} -g gdml/geometry.gdml -o none --rand-seed 123
--macro-substitutions ENERGY=1000 GENERATOR=GPS -- macros/run.mac)
set_tests_properties(basics/rand-seed PROPERTIES PASS_REGULAR_EXPRESSION
"CLHEP::HepRandom seed set to: 123")
"CLHEP::HepRandom seed changed to: 123")
Loading