-
Notifications
You must be signed in to change notification settings - Fork 30
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
Replace logger #955
Replace logger #955
Changes from all commits
72f647f
b9d2629
074a03d
8ff93ff
eeb0e51
659623c
5515ef3
26fefdb
e4ac515
8e5ef27
52c739a
bf836f5
f45bfb3
c1d749b
69235b6
519bc4a
15740cb
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 |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
#include "dawn/IIR/StencilInstantiation.h" | ||
#include "dawn/IIR/StencilMetaInformation.h" | ||
#include "dawn/Optimizer/OptimizerContext.h" | ||
#include "dawn/Support/Logging.h" | ||
#include "dawn/Support/Logger.h" | ||
|
||
#include <tuple> | ||
#include <unordered_map> | ||
|
@@ -234,8 +234,8 @@ bool PassRemoveScalars::run( | |
// Check if we have unsupported statements. If we do, warn the user and skip the pass execution. | ||
for(const auto& stmt : iterateIIROverStmt(*stencilInstantiation->getIIR())) { | ||
if(isStatementUnsupported(stmt, stencilInstantiation->getMetaData())) { | ||
DAWN_LOG(INFO) << "Unsupported statement at line " << stmt->getSourceLocation() | ||
<< ". Skipping removal of scalar variables."; | ||
DAWN_DIAG(INFO, stencilInstantiation->getMetaData().getFileName(), stmt->getSourceLocation()) | ||
<< "Unsupported statement. Skipping removal of scalar variables..."; | ||
return true; | ||
} | ||
} | ||
|
@@ -245,11 +245,9 @@ bool PassRemoveScalars::run( | |
auto removedScalars = removeScalarsFromDoMethod(*doMethod, stencilInstantiation->getMetaData()); | ||
if(context_.getOptions().ReportPassRemoveScalars) { | ||
for(const auto& varName : removedScalars) { | ||
std::cout << "PASS: " << getName() << ": " << stencilInstantiation->getName() | ||
<< ": DoMethod: " << doMethod->getID() << " removed variable: " << varName | ||
<< std::endl; | ||
DAWN_LOG(INFO) << stencilInstantiation->getName() << ": DoMethod: " << doMethod->getID() | ||
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. Switched to 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. 👍 |
||
<< " removed variable: " << varName; | ||
} | ||
std::cout.flush(); | ||
} | ||
// Recompute extents of fields | ||
doMethod->update(iir::NodeUpdateType::level); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,9 @@ | |
#include "dawn/SIR/SIR/statements.pb.h" | ||
#include "dawn/Serialization/ASTSerializer.h" | ||
#include "dawn/Serialization/SIRSerializer.h" | ||
#include "dawn/Support/Exception.h" | ||
#include "dawn/Support/Format.h" | ||
#include "dawn/Support/Logging.h" | ||
#include "dawn/Support/Logger.h" | ||
#include "dawn/Support/Unreachable.h" | ||
#include <fstream> | ||
#include <google/protobuf/util/json_util.h> | ||
|
@@ -52,10 +53,10 @@ class ProtobufLogger : public NonCopyable { | |
DAWN_LOG(WARNING) << "Protobuf: " << message; | ||
break; | ||
case google::protobuf::LOGLEVEL_ERROR: | ||
DAWN_LOG(ERROR) << "Protobuf: " << message; | ||
throw SyntacticError(std::string("[ERROR] Protobuf error: ") + message); | ||
break; | ||
case google::protobuf::LOGLEVEL_FATAL: | ||
DAWN_LOG(FATAL) << "Protobuf: " << message; | ||
throw SyntacticError(std::string("[FATAL] Protobuf error occurred: ") + message); | ||
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. This should match the other error before merging. |
||
break; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
//===--------------------------------------------------------------------------------*- C++ -*-===// | ||
// _ | ||
// | | | ||
// __| | __ ___ ___ ___ | ||
// / _` |/ _` \ \ /\ / / '_ | | ||
// | (_| | (_| |\ V V /| | | | | ||
// \__,_|\__,_| \_/\_/ |_| |_| - Compiler Toolchain | ||
// | ||
// | ||
// This file is distributed under the MIT License (MIT). | ||
// See LICENSE.txt for details. | ||
// | ||
//===------------------------------------------------------------------------------------------===// | ||
|
||
#include "dawn/Support/Logger.h" | ||
#include "dawn/Support/Assert.h" | ||
#include "dawn/Support/FileSystem.h" | ||
#include "dawn/Support/Format.h" | ||
#include <chrono> | ||
#include <iostream> | ||
|
||
namespace dawn { | ||
|
||
Logger::MessageFormatter makeMessageFormatter(const std::string type) { | ||
return [type](const std::string& msg, const std::string& file, int line) { | ||
std::stringstream ss; | ||
ss << "[" << file << ":" << line << "] "; | ||
if(type != "") | ||
ss << type << ": "; | ||
ss << msg; | ||
return ss.str(); | ||
}; | ||
} | ||
|
||
Logger::DiagnosticFormatter makeDiagnosticFormatter(const std::string type) { | ||
return [type](const std::string& msg, const std::string& file, int line, | ||
const std::string& source, SourceLocation loc) { | ||
std::stringstream ss; | ||
ss << "[" << file << ":" << line << "]"; | ||
if(source != "") | ||
ss << " " << source; | ||
if(loc.Line >= 0) { | ||
ss << ":" << loc.Line; | ||
} | ||
if(loc.Column >= 0) { | ||
ss << ":" << loc.Column; | ||
} | ||
if(type != "") | ||
ss << ": " << type; | ||
ss << ": " << msg; | ||
return ss.str(); | ||
}; | ||
} | ||
|
||
MessageProxy::MessageProxy(const MessageProxy& other) | ||
: logger_(other.logger_), ss_(other.ss_.str()), file_(other.file_), line_(other.line_) {} | ||
|
||
MessageProxy::MessageProxy(Logger& logger, const std::string& file, int line) | ||
: logger_(logger), file_(file), line_(line) {} | ||
|
||
MessageProxy::~MessageProxy() { logger_.enqueue(ss_.str(), file_, line_); } | ||
|
||
DiagnosticProxy::DiagnosticProxy(const DiagnosticProxy& other) | ||
: logger_(other.logger_), ss_(other.ss_.str()), file_(other.file_), line_(other.line_), | ||
source_(other.source_), loc_(other.loc_) {} | ||
|
||
DiagnosticProxy::DiagnosticProxy(Logger& logger, const std::string& file, int line, | ||
const std::string& source, SourceLocation loc) | ||
: logger_(logger), file_(file), line_(line), source_(source), loc_(loc) {} | ||
|
||
DiagnosticProxy::~DiagnosticProxy() { logger_.enqueue(ss_.str(), file_, line_, source_, loc_); } | ||
|
||
Logger::Logger(MessageFormatter msgFmt, DiagnosticFormatter diagFmt, std::ostream& os, bool show) | ||
: msgFmt_(msgFmt), diagFmt_(diagFmt), os_(&os), data_(), show_(show) {} | ||
|
||
MessageProxy Logger::operator()(const std::string& file, int line) { | ||
return MessageProxy(*this, file, line); | ||
} | ||
|
||
DiagnosticProxy Logger::operator()(const std::string& file, int line, const std::string& source, | ||
SourceLocation loc) { | ||
return DiagnosticProxy(*this, file, line, source, loc); | ||
} | ||
|
||
void Logger::doEnqueue(const std::string& message) { | ||
data_.push_back(message); | ||
if(show_) { | ||
*os_ << data_.back(); | ||
if(data_.back().back() != '\n') | ||
*os_ << '\n'; | ||
} | ||
} | ||
|
||
void Logger::enqueue(std::string msg, const std::string& file, int line) { | ||
doEnqueue(msgFmt_(msg, file, line)); | ||
} | ||
|
||
void Logger::enqueue(std::string msg, const std::string& file, int line, const std::string& source, | ||
SourceLocation loc) { | ||
doEnqueue(diagFmt_(msg, file, line, source, loc)); | ||
} | ||
|
||
std::ostream& Logger::stream() const { return *os_; } | ||
void Logger::stream(std::ostream& os) { os_ = &os; } | ||
|
||
Logger::MessageFormatter Logger::messageFormatter() const { return msgFmt_; } | ||
void Logger::messageFormatter(const MessageFormatter& msgFmt) { msgFmt_ = msgFmt; } | ||
|
||
Logger::DiagnosticFormatter Logger::diagnosticFormatter() const { return diagFmt_; } | ||
void Logger::diagnosticFormatter(const DiagnosticFormatter& diagFmt) { diagFmt_ = diagFmt; } | ||
|
||
void Logger::clear() { data_.clear(); } | ||
|
||
void Logger::show() { show_ = true; } | ||
void Logger::hide() { show_ = false; } | ||
|
||
// Expose container of messages | ||
Logger::iterator Logger::begin() { return std::begin(data_); } | ||
Logger::iterator Logger::end() { return std::end(data_); } | ||
Logger::const_iterator Logger::begin() const { return std::begin(data_); } | ||
Logger::const_iterator Logger::end() const { return std::end(data_); } | ||
Logger::Container::size_type Logger::size() const { return std::size(data_); } | ||
|
||
namespace log { | ||
|
||
Logger info(makeMessageFormatter("INFO"), makeDiagnosticFormatter("INFO"), std::cout, false); | ||
Logger warn(makeMessageFormatter("WARNING"), makeDiagnosticFormatter("WARNING"), std::cout, true); | ||
Logger error(makeMessageFormatter("ERROR"), makeDiagnosticFormatter("ERROR"), std::cerr, true); | ||
|
||
void setVerbosity(Level level) { | ||
switch(level) { | ||
case Level::All: | ||
info.show(); | ||
warn.show(); | ||
error.show(); | ||
break; | ||
case Level::Warnings: | ||
info.hide(); | ||
warn.show(); | ||
error.show(); | ||
break; | ||
case Level::Errors: | ||
info.hide(); | ||
warn.hide(); | ||
error.show(); | ||
break; | ||
case Level::None: | ||
info.hide(); | ||
warn.hide(); | ||
error.hide(); | ||
break; | ||
} | ||
} | ||
|
||
} // namespace log | ||
|
||
} // namespace dawn |
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.
Here is an example of the diagnostic in code.
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.
is the idea to not switch in this but in a follow up PR?