File: LogOutput.h

package info (click to toggle)
spring 103.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,720 kB
  • ctags: 63,685
  • sloc: cpp: 368,283; ansic: 33,988; python: 12,417; java: 12,203; awk: 5,879; sh: 1,846; xml: 655; perl: 405; php: 211; objc: 194; makefile: 77; sed: 2
file content (88 lines) | stat: -rw-r--r-- 1,994 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef LOG_OUTPUT_H
#define LOG_OUTPUT_H

#include <string>
#include <vector>


/**
 * @brief logging class
 * Game UI elements that display log can subscribe to it to receive the log
 * messages.
 */
class CLogOutput
{
public:
	CLogOutput();
	~CLogOutput();

	/**
	 * @brief set the log file
	 *
	 * Relative paths are relative to the writable data-dir.
	 * This method may only be called as long as the logger is not yet
	 * initialized.
	 * @see Initialize()
	 */
	void SetFileName(std::string fileName);
	/**
	 * @brief returns the log file name (without path)
	 *
	 * Relative paths are relative to the writable data-dir.
	 */
	const std::string& GetFileName() const { return fileName; }
	/**
	 * @brief returns the absolute path to the log file
	 *
	 * Relative paths are relative to the writable data-dir.
	 * This method may only be called after the logger got initialized.
	 * @see Initialize()
	 */
	const std::string& GetFilePath() const { return filePath; }

	/**
	 * @brief initialize logOutput
	 *
	 * Only after calling this method, logOutput starts writing to disk.
	 * The log file is written in the current directory so this may only be called
	 * after the engine chdir'ed to the correct directory.
	 */
	void Initialize();
	bool IsInitialized() const { return (!filePath.empty()); }


	/**
	 * Log()s system informations (CPU, 32/64bit, gcc/boost version, ...)
	 */
	static void LogSystemInfo();

private:
	/**
	 * @brief creates an absolute file path from a file name
	 *
	 * Will use the CWD, which should be the writable data-dir format
	 * absoluteification.
	 */
	static std::string CreateFilePath(const std::string& fileName);

	/**
	 * @brief moves the log file of the last run
	 *
	 * Moves the log file of the last run, to preserve it,
	 *
	 */
	void RotateLogFile() const;


	std::string fileName;
	std::string filePath;

};


extern CLogOutput logOutput;

#endif // LOG_OUTPUT_H