-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #5037 - Adjust log formatters for workflow (stdout + run.log) #5042
Changes from all commits
7e69ddf
824e6de
5bb6e24
3efa17e
95b6572
0d09c65
d7a232f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,21 +216,44 @@ void OSWorkflow::saveIDFToRootDirIfDebug() { | |
LOG(Info, "Saved IDF as " << savePath); | ||
} | ||
|
||
void standardFormatterWithStringSeverity(boost::log::record_view const& rec, boost::log::formatting_ostream& strm) { | ||
|
||
static constexpr std::array<std::string_view, 6> logLevelStrs = {"Trace", "Debug", "Info", "Warn", "Error", "Fatal"}; | ||
// static constexpr std::array<std::string_view, 6> logLevelStrs = {"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"}; | ||
|
||
LogLevel logLevel = Trace; | ||
if (auto logLevel_ = boost::log::extract<LogLevel>("Severity", rec)) { | ||
logLevel = logLevel_.get(); | ||
} | ||
|
||
// if (auto pt_ = boost::log::extract<boost::posix_time::ptime>("TimeStamp", rec)) { | ||
// // TimeStamp as [%H:%M:%S.%f] | ||
// strm << "[" << boost::posix_time::to_simple_string(pt_.get().time_of_day()) << "] "; | ||
// } | ||
strm << "[" << boost::log::extract<LogChannel>("Channel", rec) << "] <" // | ||
<< logLevelStrs[static_cast<size_t>(logLevel) - static_cast<size_t>(LogLevel::Trace)] | ||
<< "> " | ||
// Finally, the record message | ||
<< rec[boost::log::expressions::smessage]; | ||
} | ||
|
||
bool OSWorkflow::run() { | ||
|
||
// If the user passed something like `openstudio --loglevel Trace run --debug -w workflow.osw`, we retain the Trace | ||
LogLevel oriLogLevel = Warn; | ||
if (auto l_ = openstudio::Logger::instance().standardOutLogger().logLevel()) { | ||
oriLogLevel = *l_; | ||
} | ||
LogLevel oriLogLevel = openstudio::Logger::instance().standardOutLogger().logLevel().value_or(Warn); | ||
LogLevel targetLogLevel = oriLogLevel; | ||
if (workflowJSON.runOptions()->debug() && oriLogLevel > Debug) { | ||
targetLogLevel = Debug; | ||
} | ||
|
||
openstudio::Logger::instance().addTimeStampToLogger(); // Needed for run.log formatting | ||
openstudio::Logger::instance().standardOutLogger().setFormatter(&standardFormatterWithStringSeverity); | ||
|
||
// TODO: ideally we want stdErr logger to always receive Error and Fatal | ||
// and stdOut logger should receive all the others. This is definitely doable (cf LogSink::updateFilter) but now is not the time. | ||
if (!m_show_stdout) { | ||
openstudio::Logger::instance().standardOutLogger().disable(); | ||
} else if (workflowJSON.runOptions()->debug()) { | ||
openstudio::Logger::instance().standardOutLogger().setLogLevel(Error); // Still show errors | ||
Comment on lines
+252
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
} else if (oriLogLevel != targetLogLevel) { | ||
openstudio::Logger::instance().standardOutLogger().setLogLevel(targetLogLevel); | ||
} | ||
|
||
|
@@ -252,7 +275,11 @@ bool OSWorkflow::run() { | |
if (!openstudio::filesystem::is_directory(runDirPath)) { | ||
openstudio::filesystem::create_directory(runDirPath); | ||
} | ||
|
||
FileLogSink logFile(runDirPath / "run.log"); | ||
constexpr bool use_workflow_gem_fmt = true; | ||
constexpr bool include_channel = true; // or workflowJSON.runOptions()->debug(); | ||
logFile.useWorkflowGemFormatter(use_workflow_gem_fmt, include_channel); | ||
Comment on lines
+280
to
+282
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run.log: Same as the Old Ruby CLI, but with the channel in addition |
||
logFile.setLogLevel(targetLogLevel); | ||
|
||
if (hasDeletedRunDir) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stdout:
[Channel] <Debug> MSG