11 #include "G4strstreambuf.hh"
16 namespace GGSSmartLog {
18 const char *levelNames[6] = {
"",
"ERROR",
"WARNING",
"INFO",
"DEBUG",
"DEEPDEB"};
19 int verboseLevel = INFO;
20 int maxRoutineNameLength = 30;
22 const std::string &Format(
const std::string &str,
unsigned int maxLength) {
23 static std::string returnStr;
25 if (returnStr.length() > maxLength) {
26 returnStr = returnStr.substr(0, maxLength - 3).append(
"...");
38 FILE *stdoutSave =
nullptr;
39 FILE *stderrSave =
nullptr;
41 std::streambuf *cout_sbuf =
nullptr;
42 std::streambuf *cerr_sbuf =
nullptr;
48 G4ThreadLocal G4coutDestination *g4cout_dest =
nullptr;
49 G4ThreadLocal G4coutDestination *g4cerr_dest =
nullptr;
50 class MutecoutDestination :
public G4coutDestination {
52 G4int ReceiveG4cout(
const G4String &)
override {
return 0; }
53 G4int ReceiveG4cerr(
const G4String &)
override {
return 0; }
56 MutecoutDestination g4MuteDest;
57 G4ThreadLocal
bool isThreadMuted =
false;
62 FilesProxy() : fout(
"/dev/null"), muteOut(fopen(
"/dev/null",
"w")) {}
70 MutecoutDestination g4MuteDest;
82 stdout = muteFiles.muteOut;
84 stderr = muteFiles.muteOut;
86 cout_sbuf = std::cout.rdbuf();
87 cerr_sbuf = std::cerr.rdbuf();
88 std::cout.rdbuf(muteFiles.fout.rdbuf());
89 std::cerr.rdbuf(muteFiles.fout.rdbuf());
102 stderrSave =
nullptr;
106 std::cout.rdbuf(cout_sbuf);
110 std::cerr.rdbuf(cerr_sbuf);
118 void MuteG4Output() {
120 if (!isThreadMuted) {
121 g4cout_dest = G4coutbuf.GetDestination();
122 G4coutbuf.SetDestination(&muteFiles.g4MuteDest);
123 g4cerr_dest = G4cerrbuf.GetDestination();
124 G4cerrbuf.SetDestination(&muteFiles.g4MuteDest);
126 isThreadMuted =
true;
130 void UnmuteG4Output() {
132 G4coutbuf.SetDestination(g4cout_dest);
133 g4cout_dest =
nullptr;
136 G4cerrbuf.SetDestination(g4cerr_dest);
137 g4cout_dest =
nullptr;
140 isThreadMuted =
false;