Option for realtime logging with -vv

This commit is contained in:
Thomas Krijnen
2020-08-16 13:37:58 +02:00
parent f2884f9b0f
commit 45c16e5318
3 changed files with 30 additions and 9 deletions
+23 -5
View File
@@ -174,6 +174,11 @@ std::vector<IfcGeom::filter_t> setup_filters(const std::vector<geom_filter>&, co
bool init_input_file(const std::string& filename, IfcParse::IfcFile*& ifc_file, bool no_progress, bool mmap); bool init_input_file(const std::string& filename, IfcParse::IfcFile*& ifc_file, bool no_progress, bool mmap);
// from https://stackoverflow.com/questions/31696328/boost-program-options-using-zero-parameter-options-multiple-times
struct verbosity_counter {
int count;
};
#if defined(_MSC_VER) && defined(_UNICODE) #if defined(_MSC_VER) && defined(_UNICODE)
int wmain(int argc, wchar_t** argv) { int wmain(int argc, wchar_t** argv) {
typedef po::wcommand_line_parser command_line_parser; typedef po::wcommand_line_parser command_line_parser;
@@ -197,10 +202,11 @@ int main(int argc, char** argv) {
std::string log_format; std::string log_format;
po::options_description generic_options("Command line options"); po::options_description generic_options("Command line options");
verbosity_counter vcounter;
generic_options.add_options() generic_options.add_options()
("help,h", "display usage information") ("help,h", "display usage information")
("version", "display version information") ("version", "display version information")
("verbose,v", "more verbose log messages") ("verbose,v", po::value(&vcounter)->zero_tokens(), "more verbose log messages")
("quiet,q", "less status and progress output") ("quiet,q", "less status and progress output")
("stderr-progress", "output progress to stderr stream") ("stderr-progress", "output progress to stderr stream")
("yes,y", "answer 'yes' automatically to possible confirmation queries (e.g. overwriting an existing output file)") ("yes,y", "answer 'yes' automatically to possible confirmation queries (e.g. overwriting an existing output file)")
@@ -403,7 +409,6 @@ int main(int argc, char** argv) {
po::notify(vmap); po::notify(vmap);
const bool mmap = vmap.count("mmap") != 0; const bool mmap = vmap.count("mmap") != 0;
const bool verbose = vmap.count("verbose") != 0;
const bool no_progress = vmap.count("no-progress") != 0; const bool no_progress = vmap.count("no-progress") != 0;
const bool quiet = vmap.count("quiet") != 0; const bool quiet = vmap.count("quiet") != 0;
const bool stderr_progress = vmap.count("stderr-progress") != 0; const bool stderr_progress = vmap.count("stderr-progress") != 0;
@@ -539,8 +544,13 @@ int main(int argc, char** argv) {
} }
} }
Logger::SetOutput(quiet ? nullptr : &cout_, &log_stream); Logger::SetOutput(quiet ? nullptr : &cout_, vcounter.count > 1 ? &cout_ : &log_stream);
Logger::Verbosity(verbose ? Logger::LOG_NOTICE : Logger::LOG_ERROR); Logger::Verbosity(vcounter.count
? (vcounter.count > 1
? Logger::LOG_DEBUG
: Logger::LOG_NOTICE)
: Logger::LOG_ERROR
);
path_t output_temp_filename = output_filename + IfcUtil::path::from_utf8(TEMP_FILE_EXTENSION); path_t output_temp_filename = output_filename + IfcUtil::path::from_utf8(TEMP_FILE_EXTENSION);
@@ -757,7 +767,7 @@ int main(int argc, char** argv) {
Logger::Status("Creating geometry..."); Logger::Status("Creating geometry...");
} }
Logger::SetOutput(quiet ? nullptr : &cout_, &log_stream); Logger::SetOutput(quiet ? nullptr : &cout_, vcounter.count > 1 ? &cout_ : &log_stream);
if (model_rotation) { if (model_rotation) {
std::array<double, 4> &rotation = settings.rotation; std::array<double, 4> &rotation = settings.rotation;
@@ -913,6 +923,9 @@ int main(int argc, char** argv) {
cout_ << std::flush; cout_ << std::flush;
if (stderr_progress) if (stderr_progress)
cerr_ << std::flush; cerr_ << std::flush;
} else if (vcounter.count == 2) {
const int progress = context_iterator.progress();
Logger::Message(Logger::LOG_DEBUG, "Progress " + boost::lexical_cast<std::string>(progress));
} else { } else {
const int progress = context_iterator.progress() / 2; const int progress = context_iterator.progress() / 2;
if (old_progress != progress) Logger::ProgressBar(progress); if (old_progress != progress) Logger::ProgressBar(progress);
@@ -1119,6 +1132,11 @@ void parse_filter(geom_filter &filter, const std::vector<std::string>& values)
filter.values.insert(values.begin() + (filter.type == geom_filter::ENTITY_ARG ? 2 : 1), values.end()); filter.values.insert(values.begin() + (filter.type == geom_filter::ENTITY_ARG ? 2 : 1), values.end());
} }
void validate(boost::any& v, const std::vector<std::string>& values, verbosity_counter*, long) {
if (v.empty()) v = verbosity_counter{ 1 };
else ++boost::any_cast<verbosity_counter&>(v).count;
}
void validate(boost::any& v, const std::vector<std::string>& values, inclusion_filter*, int) void validate(boost::any& v, const std::vector<std::string>& values, inclusion_filter*, int)
{ {
/// @todo For now only single --include, --include+, --exclude, or --exclude+ supported. Support having multiple. /// @todo For now only single --include, --include+, --exclude, or --exclude+ supported. Support having multiple.
+6 -3
View File
@@ -37,14 +37,14 @@ namespace {
template <typename T> template <typename T>
struct severity_strings { struct severity_strings {
static const std::array<std::basic_string<T>, 3> value; static const std::array<std::basic_string<T>, 4> value;
}; };
template <> template <>
const std::array<std::basic_string<char>, 3> severity_strings<char>::value = { "Notice", "Warning", "Error" }; const std::array<std::basic_string<char>, 4> severity_strings<char>::value = { "Debug", "Notice", "Warning", "Error" };
template <> template <>
const std::array<std::basic_string<wchar_t>, 3> severity_strings<wchar_t>::value = { L"Notice", L"Warning", L"Error" }; const std::array<std::basic_string<wchar_t>, 4> severity_strings<wchar_t>::value = { L"Debug", L"Notice", L"Warning", L"Error" };
template <typename T> template <typename T>
void plain_text_message(T& os, const boost::optional<IfcUtil::IfcBaseClass*>& current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseClass* instance) { void plain_text_message(T& os, const boost::optional<IfcUtil::IfcBaseClass*>& current_product, Logger::Severity type, const std::string& message, const IfcUtil::IfcBaseClass* instance) {
@@ -93,6 +93,9 @@ namespace {
} }
void Logger::SetProduct(boost::optional<IfcUtil::IfcBaseClass*> product) { void Logger::SetProduct(boost::optional<IfcUtil::IfcBaseClass*> product) {
if (verbosity == LOG_DEBUG && product) {
Message(LOG_DEBUG, "Begin processing", *product);
}
current_product = product; current_product = product;
} }
+1 -1
View File
@@ -35,7 +35,7 @@
class IFC_PARSE_API Logger { class IFC_PARSE_API Logger {
public: public:
typedef enum { LOG_NOTICE, LOG_WARNING, LOG_ERROR } Severity; typedef enum { LOG_DEBUG, LOG_NOTICE, LOG_WARNING, LOG_ERROR } Severity;
typedef enum { FMT_PLAIN, FMT_JSON } Format; typedef enum { FMT_PLAIN, FMT_JSON } Format;
private: private: