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