The Battle for Wesnoth  1.15.11+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 filesystem
42 {
43 
44 /**
45  * Returns the path to the permanent log storage directory.
46  */
47 std::string get_logs_dir();
48 
49 }
50 
51 namespace lg
52 {
53 
54 /**
55  * Returns the path to the current log file.
56  *
57  * An empty string is returned if the log file has not been set up yet or it
58  * was disabled (e.g. by --wconsole).
59  */
60 std::string log_file_path();
61 
62 /**
63  * Sets up the initial temporary log file.
64  *
65  * This has to be done on demand (preferably as early as possible) from a
66  * function rather than during static initialization, otherwise things go
67  * horribly wrong as soon as we try to use the logging facilities internally
68  * for debug messages.
69  */
70 void early_log_file_setup(bool disable);
71 
72 /**
73  * Relocates the stdout+stderr log file to the user data directory.
74  *
75  * This function exits the process if something goes wrong (including calling
76  * it when the user data directory isn't known yet).
77  */
79 
80 /**
81  * Switches to using a native console instead of log file redirection.
82  *
83  * In this mode, the log file is closed (if it was created in the first place)
84  * and output is sent directly to an attached or allocated console instead.
85  * This is used to implement the --wconsole command line option.
86  *
87  * Using a native console instead of a file has the benefit of allowing to see
88  * output in real time or redirecting it to a user-specified file.
89  */
91 
92 /**
93  * Returns true if a console was allocated by the Wesnoth process.
94  * Returns false if no native console or if it was attached from a parent process.
95  */
96 bool using_own_console();
97 
98 }
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:48
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:39