diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 73c767dad2..0e2dce5f77 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -184,9 +184,12 @@ if (WIN32) if(MSVC) target_link_options(OrcaSlicer_app_gui PUBLIC "$<$:/DEBUG>") endif() - target_compile_definitions(OrcaSlicer_app_gui PRIVATE -DSLIC3R_WRAPPER_NOCONSOLE) + target_compile_definitions(OrcaSlicer_app_gui PRIVATE "$<$>:SLIC3R_WRAPPER_NOCONSOLE>") add_dependencies(OrcaSlicer_app_gui OrcaSlicer) - set_target_properties(OrcaSlicer_app_gui PROPERTIES OUTPUT_NAME "orca-slicer") + set_target_properties(OrcaSlicer_app_gui PROPERTIES + OUTPUT_NAME "orca-slicer" + WIN32_EXECUTABLE "$>" + ) target_link_libraries(OrcaSlicer_app_gui PRIVATE boost_headeronly) endif () diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 9b67d7ab50..93946ca477 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -534,6 +534,7 @@ endif () encoding_check(libslic3r) target_compile_definitions(libslic3r PUBLIC -DUSE_TBB -DTBB_USE_CAPTURED_EXCEPTION=0) +target_compile_definitions(libslic3r PRIVATE $<$:SLIC3R_CONSOLE_LOG>) target_include_directories(libslic3r PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(libslic3r SYSTEM PUBLIC ${EXPAT_INCLUDE_DIRS}) diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index f1bdd89712..fee9f2e5ac 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -194,6 +194,7 @@ std::string debug_out_path(const char *name, ...); // smaller level means less log. level=5 means saving all logs. void set_log_path_and_level(const std::string& file, unsigned int level); void flush_logs(); +void shutdown_console_logging(); boost::filesystem::path get_log_file_name(); // A special type for strings encoded in the local Windows 8-bit code page. diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index 42dcc14878..f3edb516ab 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -46,14 +47,19 @@ #include #include #include +#include #include +#include #include #include #include #include #include +#include #include +#include +#include #include #include @@ -174,6 +180,7 @@ unsigned get_logging_level() } boost::shared_ptr> g_log_sink; +boost::shared_ptr> g_console_log_sink; // Force set_logging_level(<=error) after loading of the DLL. // This is currently only needed if libslic3r is loaded as a shared library into Perl interpreter @@ -346,6 +353,19 @@ namespace src = boost::log::sources; namespace expr = boost::log::expressions; namespace keywords = boost::log::keywords; namespace attrs = boost::log::attributes; +namespace sinks = boost::log::sinks; + +void shutdown_console_logging() +{ + if (!g_console_log_sink) + return; + + auto console_sink = g_console_log_sink; + boost::log::core::get()->remove_sink(console_sink); + console_sink->stop(); + g_console_log_sink.reset(); +} + void set_log_path_and_level(const std::string& file, unsigned int level) { #ifdef __APPLE__ @@ -377,6 +397,24 @@ void set_log_path_and_level(const std::string& file, unsigned int level) keywords::auto_flush = true ); + shutdown_console_logging(); + +#ifdef SLIC3R_CONSOLE_LOG + auto console_backend = boost::make_shared(); + console_backend->add_stream(boost::shared_ptr(&std::cout, boost::null_deleter())); + console_backend->auto_flush(true); + + g_console_log_sink = boost::make_shared>(console_backend); + g_console_log_sink->set_formatter( + expr::stream + << "[" << expr::attr< logging::trivial::severity_level >("Severity") << "]\t" + << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S.%f") << " " + <<"[Thread " << expr::attr("ThreadID") << "]" + << ": " << expr::smessage + ); + boost::log::core::get()->add_sink(g_console_log_sink); +#endif + logging::add_common_attributes(); set_logging_level(level); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index fde56fe39e..fb9aeb339e 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2261,6 +2261,7 @@ GUI_App::~GUI_App() BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(": exit"); + shutdown_console_logging(); } bool GUI_App::is_blocking_printing(MachineObject *obj_)