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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef LOG_OUTPUT_H
#define LOG_OUTPUT_H
#include "lib/gml/gmlcnf.h"
#if defined(USE_GML) && GML_ENABLE_SIM
#include <boost/thread/mutex.hpp>
#endif
#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;
/**
* @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;
/**
* @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();
private:
void End();
/**
* @brief initialize the log sections
*
* This writes a list of all available and all enabled sections to the log.
*
* Log sections can be enabled using the configuration key "LogSections",
* or the environment variable "SPRING_LOG_SECTIONS".
*
* Both specify a comma separated list of sections that should be enabled.
* The lists from both sources are combined, there is no overriding.
*
* A section that is enabled by default, can not be disabled.
*/
void InitializeSections();
/**
* @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 enable/disable log file rotation
*
* The default is determined by the config setting RotateLogFiles and
* whether this is a DEBUG build or not.
* RotateLogFiles defaults to "auto", and could be set to "never"
* or "always". On "auto", it will rotate logs only for debug builds.
* You may only call this as long as the logger did not yet get initialized.
*/
void SetLogFileRotating(bool enabled);
bool IsLogFileRotating() const;
/**
* @brief ff enabled, moves the log file of the last run
*
* Moves the log file of the last run, to preserve it,
* if log file rotation is enabled.
*
* By default, this is enabled only for DEBUG builds;
* ... (describe config file value here)
*/
void RotateLogFile() const;
std::string fileName;
std::string filePath;
bool rotateLogFiles;
#if defined(USE_GML) && GML_ENABLE_SIM
boost::mutex logmutex;
#endif
};
extern CLogOutput logOutput;
#endif // LOG_OUTPUT_H
|