The Battle for Wesnoth  1.15.2+dev
log_windows.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Iris Morelle <shadowm2006@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include <string>
18 
19 /**
20  * @file
21  * Log file control routines for Windows.
22  *
23  * During static object initialization, stdout and stderr are redirected to a
24  * uniquely-named log file located in the user's temporary directory as defined
25  * by the platform (e.g. C:/Users/username/AppData/Local/Temp/wesnoth-XXXX.log).
26  * Later, a request may be issued to relocate the log file to a more permanent
27  * and user-accessible location (such as the Wesnoth user data directory).
28  *
29  * Because Wesnoth is normally built with the GUI subsystem option, there is no
30  * console on startup and thus no way to see stdout/stderr output. Since
31  * version 1.13.1, we can allocate a console during initialization when started
32  * with the --wconsole option, but that is a somewhat clunky hack that does not
33  * help with post mortem debugging.
34  *
35  * SDL 1.2 used to redirect stdout and stderr to stdout.txt and stderr.txt in
36  * the process working directory automatically, but this approach too had its
37  * own shortcomings by assuming the pwd was writable by the process (or in Vista
38  * and later versions, requiring UAC virtualization to be enabled).
39  */
40 
41 namespace lg
42 {
43 
44 /**
45  * Returns the path to the current log file.
46  *
47  * An empty string is returned if the log file has not been set up yet or it
48  * was disabled (e.g. by --wconsole).
49  */
50 std::string log_file_path();
51 
52 /**
53  * Sets up the initial temporary log file.
54  *
55  * This has to be done on demand (preferably as early as possible) from a
56  * function rather than during static initialization, otherwise things go
57  * horribly wrong as soon as we try to use the logging facilities internally
58  * for debug messages.
59  */
61 
62 /**
63  * Relocates the stdout+stderr log file to the user data directory.
64  *
65  * This function exits the process if something goes wrong (including calling
66  * it when the user data directory isn't known yet).
67  */
69 
70 /**
71  * Switches to using a native console instead of log file redirection.
72  *
73  * In this mode, the log file is closed (if it was created in the first place)
74  * and output is sent directly to an attached or allocated console instead.
75  * This is used to implement the --wconsole command line option.
76  *
77  * Using a native console instead of a file has the benefit of allowing to see
78  * output in real time or redirecting it to a user-specified file.
79  */
81 
82 /**
83  * Returns true if a console was allocated by the Wesnoth process.
84  * Returns false if no native console or if it was attached from a parent process.
85  */
86 bool using_own_console();
87 
88 }
bool using_own_console()
Returns true if a console was allocated by the Wesnoth process.
std::string log_file_path()
Returns the path to the current log file.
void finish_log_file_setup()
Relocates the stdout+stderr log file to the user data directory.
void early_log_file_setup()
Sets up the initial temporary log file.
void enable_native_console_output()
Switches to using a native console instead of log file redirection.
Definition: pump.hpp:39