30 #include <boost/algorithm/string/predicate.hpp>
36 #define WIN32_LEAN_AND_MEAN
41 #define ERR_LS LOG_STREAM(err, log_setup)
42 #define WRN_LS LOG_STREAM(warn, log_setup)
43 #define LOG_LS LOG_STREAM(info, log_setup)
44 #define DBG_LS LOG_STREAM(debug, log_setup)
57 console_handler(
const console_handler&) =
delete;
58 console_handler& operator=(
const console_handler&) =
delete;
65 bool owns_console()
const;
73 void enable_native_console_output();
76 console_handler::console_handler()
77 : created_wincon_(
false)
79 DBG_LS <<
"Early init message";
81 if(GetConsoleWindow() !=
nullptr) {
85 LOG_LS <<
"Console already attached at startup (built with console subsystem flag?), log file disabled.";
87 enable_native_console_output();
90 DBG_LS <<
"Windows console init complete!";
93 bool console_handler::owns_console()
const
95 return created_wincon_;
98 void console_handler::enable_native_console_output()
100 if(AttachConsole(ATTACH_PARENT_PROCESS)) {
101 LOG_LS <<
"Attached parent process console.";
102 }
else if(AllocConsole()) {
103 LOG_LS <<
"Allocated own console.";
104 created_wincon_ =
true;
111 WRN_LS <<
"Cannot attach or allocate a console, continuing anyway (is this Wine?)";
114 DBG_LS <<
"stderr to console";
117 assert(freopen(
"CONOUT$",
"wb", stderr) == stderr);
119 DBG_LS <<
"stdout to console";
122 assert(freopen(
"CONOUT$",
"wb", stdout) == stdout);
124 DBG_LS <<
"stdin from console";
125 assert(freopen(
"CONIN$",
"rb", stdin) == stdin);
127 LOG_LS <<
"Console streams handover complete!";
130 std::unique_ptr<console_handler> lfm;
137 lfm.reset(
new console_handler());
143 return lfm && lfm->owns_console();
Declarations for File-IO.
Standard logging facilities (interface).
static lg::log_domain log_setup("logsetup")
bool using_own_console()
Returns true if a console was allocated by the Wesnoth process.
void do_console_redirect()
Allocates a console if needed and redirects output to CONOUT.