From c6c358dc394d646f16c733d58b02600a2dfead81 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 15 Apr 2024 16:42:27 +0100 Subject: [PATCH 1/5] Added -r support for using vsg::Loger::redirect_std() support to redirect std::cout and std::cout to vsg::Logger --- examples/io/vsglog/vsglog.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/io/vsglog/vsglog.cpp b/examples/io/vsglog/vsglog.cpp index 9b61b9f1..a65d8c7c 100644 --- a/examples/io/vsglog/vsglog.cpp +++ b/examples/io/vsglog/vsglog.cpp @@ -46,7 +46,12 @@ int main(int argc, char** argv) // you can override the message verbosity by setting the minimum level that will be printed. vsg::Logger::instance()->level = level; + // if we want to redirect std::cout and std::cerr to the vsg::Logger call vsg::Logger::redirect_stdout() + if (arguments.read({"--redirect-std", "-r"})) vsg::Logger::instance()->redirect_std(); + // simplest form of messaging gets passed to the vsg::Logger::instance(). + std::cout<<"cout cstring"< Date: Tue, 16 Apr 2024 08:48:42 +0100 Subject: [PATCH 2/5] Simplified console output to just use fprintf rather std::cout/cerr to avoid potential confusion over new ability to redirect std::cout/cerr. --- examples/io/vsglog/vsglog.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/io/vsglog/vsglog.cpp b/examples/io/vsglog/vsglog.cpp index a65d8c7c..2ae63e9c 100644 --- a/examples/io/vsglog/vsglog.cpp +++ b/examples/io/vsglog/vsglog.cpp @@ -10,27 +10,27 @@ class CustomLogger : public vsg::Inherit protected: void debug_implementation(const std::string_view& message) override { - std::cout<<"custom debug : "<(message.length()), message.data()); } void info_implementation(const std::string_view& message) override { - std::cout<<"custom info : "<(message.length()), message.data()); } void warn_implementation(const std::string_view& message) override { - std::cerr<<"custom warn : "<(message.length()), message.data()); } void error_implementation(const std::string_view& message) override { - std::cerr<<"custom error : "<(message.length()), message.data()); } void fatal_implementation(const std::string_view& message) override { - std::cerr<<"custom error : "<(message.length()), message.data()); throw vsg::Exception{std::string(message)}; } }; From 7ce5f140c81069492c56bd6f74458f292d093bf6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 16 Apr 2024 09:05:29 +0100 Subject: [PATCH 3/5] Added -r command line option to enable Logger::redirect_std(). --- examples/io/vsglog_mt/vsglog_mt.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/io/vsglog_mt/vsglog_mt.cpp b/examples/io/vsglog_mt/vsglog_mt.cpp index 7769550a..49f2883c 100644 --- a/examples/io/vsglog_mt/vsglog_mt.cpp +++ b/examples/io/vsglog_mt/vsglog_mt.cpp @@ -12,6 +12,7 @@ struct MyOperation : public vsg::Inherit auto level = vsg::Logger::Level(1 + value % 4); vsg::info("info() operation ",value); vsg::log(level, "log() operation ",value); + std::cout<<"cout operation"<setThreadPrefix(std::this_thread::get_id(), "main | "); vsg::CommandLine arguments(&argc, argv); + + // if we want to redirect std::cout and std::cerr to the vsg::Logger call vsg::Logger::redirect_stdout() + if (arguments.read({"--redirect-std", "-r"})) vsg::Logger::instance()->redirect_std(); + auto numThreads = arguments.value(16, "-t"); auto count = arguments.value(100, "-n"); auto level = vsg::Logger::Level(arguments.value(0, "-l")); From c2cbc012b44edbf0bc21333aead5e7aafaeec4b9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 16 Apr 2024 11:38:57 +0100 Subject: [PATCH 4/5] Added -r command line option for enablig the Logger::redirect_std() --- examples/app/vsgviewer/vsgviewer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/app/vsgviewer/vsgviewer.cpp b/examples/app/vsgviewer/vsgviewer.cpp index d8bef17b..5190715d 100644 --- a/examples/app/vsgviewer/vsgviewer.cpp +++ b/examples/app/vsgviewer/vsgviewer.cpp @@ -50,6 +50,9 @@ int main(int argc, char** argv) // set up defaults and read command line arguments to override them vsg::CommandLine arguments(&argc, argv); + // if we want to redirect std::cout and std::cerr to the vsg::Logger call vsg::Logger::redirect_stdout() + if (arguments.read({"--redirect-std", "-r"})) vsg::Logger::instance()->redirect_std(); + // set up vsg::Options to pass in filepaths, ReaderWriters and other IO related options to use when reading and writing files. auto options = vsg::Options::create(); options->sharedObjects = vsg::SharedObjects::create(); From 1a010c69ca2a25b47a3710088e433de75a9d1dce Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 16 Apr 2024 11:39:42 +0100 Subject: [PATCH 5/5] Added number of the std::cout messages --- examples/io/vsglog_mt/vsglog_mt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/io/vsglog_mt/vsglog_mt.cpp b/examples/io/vsglog_mt/vsglog_mt.cpp index 49f2883c..c9b7024c 100644 --- a/examples/io/vsglog_mt/vsglog_mt.cpp +++ b/examples/io/vsglog_mt/vsglog_mt.cpp @@ -12,7 +12,7 @@ struct MyOperation : public vsg::Inherit auto level = vsg::Logger::Level(1 + value % 4); vsg::info("info() operation ",value); vsg::log(level, "log() operation ",value); - std::cout<<"cout operation"<