40 String_V split(
const G4String& input,
char separator =
'\n')
43 G4String::size_type prev_pos = 0,
pos = 0;
44 while((pos = input.find(separator, pos)) != G4String::npos)
47 output.emplace_back(input.substr(prev_pos, pos - prev_pos));
56 G4bool transform(G4String& input,
const G4String& type)
58 std::time_t result = std::time(
nullptr);
59 std::ostringstream newm;
61 newm << std::put_time(std::localtime(&result),
"%d/%b/%Y:%H:%M:%S %z");
63 std::tm* time_ = std::localtime(&result);
64 newm << time_->tm_mday <<
"/" << time_->tm_mon <<
"/" << time_->tm_year;
65 newm <<
":" << time_->tm_hour <<
":" << time_->tm_min <<
":"
68 newm <<
" " << type <<
" [";
69 G4String delimiter =
"";
70 for(
const auto& el : split(input))
74 newm << delimiter << el;
85 G4String masterStyle =
"";
93 dest->AddCoutTransformer(
94 std::bind(&transform, std::placeholders::_1,
"INFO"));
95 dest->AddCerrTransformer(
96 std::bind(&transform, std::placeholders::_1,
"ERROR"));
106 dest->ResetTransformers();
111 std::unordered_map<std::string, SetupStyle_f> transformers = {
112 { ID::SYSLOG, SysLogStyle },
113 { ID::DEFAULT, DefaultStyle }
132 for(
const auto& el : transformers)
134 result.push_back(el.first);
141 const auto& handler = transformers.find(style);
142 return (handler != transformers.cend()) ? (handler->second)(dest) : -1;
147 if(transformers.find(name) != transformers.cend())
150 msg <<
"Format Style with name " << name
151 <<
" already exists. Replacing existing.";
152 G4Exception(
"G4coutFormatters::RegisterNewStyle()",
"FORMATTER001",
156 transformers[name] = fmt;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
void G4iosSetDestination(G4coutDestination *sink)