1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

- Removed some documentation comments

This commit is contained in:
beegee1 2013-04-06 18:34:06 +00:00
parent de01ea54b0
commit 1bb79ed187
8 changed files with 121 additions and 228 deletions

View File

@ -16,9 +16,8 @@
class CConsoleHandler;
/**
* The basic log configurator reads log properties from the settings.json and
* sets up the logging system. The file path of the log file can be specified
* via the constructor.
* The basic log configurator reads log properties from settings.json and
* sets up the logging system.
*/
class DLL_LINKAGE CBasicLogConfigurator
{
@ -26,30 +25,16 @@ public:
/**
* Constructor.
*
* @param fileName The file path of the log file.
* @param filePath The file path of the log file.
* @param console The console handler to log messages to the console. The handler should be initialized.
*
* @throws std::runtime_error if the configuration has errors
*/
CBasicLogConfigurator(const std::string & filePath, CConsoleHandler * console);
private:
/**
* Gets the log level enum from a string.
*
* @param level The log level string to parse.
* @return the corresponding log level enum value
*
* @throws std::runtime_error if the log level is unknown
*/
ELogLevel::ELogLevel getLogLevel(const std::string & level) const;
// Methods
/**
* Gets the console text color enum from a string.
*
* @param colorName The color string to parse.
* @return the corresponding console text color enum value
*
* @throws std::runtime_error if the log level is unknown
*/
ELogLevel::ELogLevel getLogLevel(const std::string & level) const;
EConsoleTextColor::EConsoleTextColor getConsoleColor(const std::string & colorName) const;
};

View File

@ -29,6 +29,8 @@ public:
*/
CColorMapping();
// Methods
/**
* Sets a console text color for a logger name and a level.
*
@ -48,7 +50,8 @@ public:
EConsoleTextColor::EConsoleTextColor getColorFor(const CLoggerDomain & domain, ELogLevel::ELogLevel level) const;
private:
/** The color mapping, 1. Key: Logger domain, 2. Key: Level, Value: Color. */
// Data members
std::map<std::string, std::map<ELogLevel::ELogLevel, EConsoleTextColor::EConsoleTextColor> > map;
};
@ -65,83 +68,36 @@ public:
*/
explicit CLogConsoleTarget(CConsoleHandler * console);
// Accessors
bool isColoredOutputEnabled() const;
void setColoredOutputEnabled(bool coloredOutputEnabled);
ELogLevel::ELogLevel getThreshold() const;
void setThreshold(ELogLevel::ELogLevel threshold);
const CLogFormatter & getFormatter() const;
void setFormatter(const CLogFormatter & formatter);
const CColorMapping & getColorMapping() const;
void setColorMapping(const CColorMapping & colorMapping);
// Methods
/**
* Writes a log record.
* Writes a log record to the console.
*
* @param record The log record to write.
*/
void write(const LogRecord & record);
/**
* True if colored output is enabled.
*
* @return true if colored output is enabled, false if not
*/
bool isColoredOutputEnabled() const;
/**
* Sets the colored output flag.
*
* @param coloredOutput True if the log target should write colored messages to the console, false if not.
*/
void setColoredOutputEnabled(bool coloredOutputEnabled);
/**
* Gets the threshold log level.
*
* @return the threshold log level
*/
ELogLevel::ELogLevel getThreshold() const;
/**
* Sets the threshold log level.
*
* @param threshold The threshold log level.
*/
void setThreshold(ELogLevel::ELogLevel threshold);
/**
* Gets the log formatter.
*
* @return The log formatter.
*/
const CLogFormatter & getFormatter() const;
/**
* Sets the log formatter.
*
* @param formatter The log formatter.
*/
void setFormatter(const CLogFormatter & formatter);
/**
* Gets the color mapping.
*/
const CColorMapping & getColorMapping() const;
/**
* Sets the color mapping.
*
* @param colorMapping The color mapping.
*/
void setColorMapping(const CColorMapping & colorMapping);
private:
/** The console handler which is used to output messages to the console. */
// Data members
CConsoleHandler * console;
/** The threshold log level. */
ELogLevel::ELogLevel threshold;
/** Flag whether colored console output is enabled. */
bool coloredOutputEnabled;
/** The log formatter to log messages. */
CLogFormatter formatter;
/** The color mapping which maps a logger and a log level to a color. */
CColorMapping colorMapping;
/** The shared mutex for providing synchronous thread-safe access to the log console target. */
mutable boost::mutex mx;
};

View File

@ -26,41 +26,27 @@ public:
* @param filePath The file path of the log file.
*/
explicit CLogFileTarget(const std::string & filePath);
/**
* Destructor.
*/
~CLogFileTarget();
// Accessors
const CLogFormatter & getFormatter() const;
void setFormatter(const CLogFormatter & formatter);
// Methods
/**
* Writes a log record.
* Writes a log record to the log file.
*
* @param record The log record to write.
*/
void write(const LogRecord & record);
/**
* Gets the log formatter.
*
* @return The log formatter.
*/
const CLogFormatter & getFormatter() const;
/**
* Sets the log formatter.
*
* @param formatter The log formatter.
*/
void setFormatter(const CLogFormatter & formatter);
private:
/** The output file stream. */
// Data members
std::ofstream file;
/** The log formatter to log messages. */
CLogFormatter formatter;
/** The shared mutex for providing synchronous thread-safe access to the log file target. */
mutable boost::mutex mx;
};

View File

@ -26,9 +26,6 @@ struct LogRecord;
class DLL_LINKAGE CLogFormatter
{
public:
/**
* Default constructor.
*/
CLogFormatter();
/**
@ -38,6 +35,13 @@ public:
*/
CLogFormatter(const std::string & pattern);
// Accessors
void setPattern(const std::string & pattern);
const std::string & getPattern() const;
// Methods
/**
* Formats a log record.
*
@ -46,21 +50,9 @@ public:
*/
std::string format(const LogRecord & record) const;
/**
* Sets the pattern.
*
* @param pattern The pattern string which describes how to format the log record.
*/
void setPattern(const std::string & pattern);
/**
* Gets the pattern.
*
* @return the pattern string which describes how to format the log record
*/
const std::string & getPattern() const;
private:
/** The pattern string which describes how to format the log record. */
// Data members
std::string pattern;
};

View File

@ -20,6 +20,10 @@ class CLoggerDomain;
class DLL_LINKAGE CLogManager : public boost::noncopyable
{
public:
~CLogManager();
// Methods
/**
* Gets an instance of the log manager.
*
@ -42,26 +46,15 @@ public:
*/
CGLogger * getLogger(const CLoggerDomain & domain);
/**
* Destructor.
*/
~CLogManager();
private:
/**
* Constructor.
*/
// Methods
CLogManager();
/** The instance of the log manager. */
// Data members
static CLogManager * instance;
/** The loggers map where the key is the logger name and the value the corresponding logger. */
std::map<std::string, CGLogger *> loggers;
/** The shared mutex for providing synchronous thread-safe access to the log manager. */
mutable boost::shared_mutex mx;
/** The unique mutex for providing thread-safe singleton access. */
static boost::mutex smx;
};

View File

@ -17,9 +17,6 @@ class ILogTarget;
namespace ELogLevel
{
/**
* The log level enum holds various log level definitions.
*/
enum ELogLevel
{
NOT_SET = 0,
@ -40,10 +37,16 @@ public:
/**
* Constructor.
*
* @param domain The domain name. Sub-domains can be specified by separating domains by a dot, e.g. "ai.battle". The global domain is named "global".
* @param name The domain name. Sub-domains can be specified by separating domains by a dot, e.g. "ai.battle". The global domain is named "global".
*/
CLoggerDomain(const std::string & name);
// Accessors
std::string getName() const;
// Methods
/**
* Gets the parent logger domain.
*
@ -58,18 +61,12 @@ public:
*/
bool isGlobalDomain() const;
/**
* Gets the name of the domain.
*
* @return the name of the domain
*/
std::string getName() const;
// Constants
/** Constant to the global domain name. */
static const std::string DOMAIN_GLOBAL;
private:
/** The domain name. */
std::string name;
};
@ -81,9 +78,22 @@ class CGLogger;
class DLL_LINKAGE CLoggerStream
{
public:
/**
* Constructs a new logger stream.
*
* @param logger The logger which should be used to log the generated message to.
* @param level The log level of the generated message.
*/
CLoggerStream(const CGLogger & logger, ELogLevel::ELogLevel level);
~CLoggerStream();
// Methods
/**
* Writes data to the logger stream.
*
* @param data Any data can be written to the stream.
*/
template<typename T>
CLoggerStream & operator<<(const T & data)
{
@ -93,6 +103,8 @@ public:
}
private:
// Data members
const CGLogger & logger;
ELogLevel::ELogLevel level;
std::stringstream * sbuffer;
@ -105,6 +117,17 @@ private:
class DLL_LINKAGE CGLogger : public boost::noncopyable
{
public:
~CGLogger();
// Accessors
inline ELogLevel::ELogLevel getLevel() const;
void setLevel(ELogLevel::ELogLevel level);
const CLoggerDomain & getDomain() const;
// Methods
/**
* Gets a logger by domain.
*
@ -127,6 +150,11 @@ public:
*/
void trace(const std::string & message) const;
/**
* Returns a logger stream with the trace level.
*
* @return the logger stream
*/
CLoggerStream traceStream() const;
/**
@ -136,6 +164,11 @@ public:
*/
void debug(const std::string & message) const;
/**
* Returns a logger stream with the debug level.
*
* @return the logger stream
*/
CLoggerStream debugStream() const;
/**
@ -145,6 +178,11 @@ public:
*/
void info(const std::string & message) const;
/**
* Returns a logger stream with the info level.
*
* @return the logger stream
*/
CLoggerStream infoStream() const;
/**
@ -154,6 +192,11 @@ public:
*/
void warn(const std::string & message) const;
/**
* Returns a logger stream with the warn level.
*
* @return the logger stream
*/
CLoggerStream warnStream() const;
/**
@ -163,6 +206,11 @@ public:
*/
void error(const std::string & message) const;
/**
* Returns a logger stream with the error level.
*
* @return the logger stream
*/
CLoggerStream errorStream() const;
/**
@ -173,27 +221,6 @@ public:
*/
inline void log(ELogLevel::ELogLevel level, const std::string & message) const;
/**
* Gets the log level applied for this logger. The default level for the root logger is INFO.
*
* @return the log level
*/
inline ELogLevel::ELogLevel getLevel() const;
/**
* Sets the log level.
*
* @param level The log level.
*/
void setLevel(ELogLevel::ELogLevel level);
/**
* Gets the logger domain.
*
* @return the domain of the logger
*/
const CLoggerDomain & getDomain() const;
/**
* Adds a target to this logger and indirectly to all loggers which derive from this logger.
* The logger holds strong-ownership of the target object.
@ -202,64 +229,21 @@ public:
*/
void addTarget(ILogTarget * target);
/**
* Destructor.
*/
~CGLogger();
private:
/**
* Constructor.
*
* @param domain The domain of the logger.
*/
// Methods
explicit CGLogger(const CLoggerDomain & domain);
/**
* Gets the parent logger.
*
* @return the parent logger or nullptr if this is the root logger
*/
CGLogger * getParent() const;
/**
* Gets the effective log level.
*
* @return the effective log level with respect to parent log levels
*/
inline ELogLevel::ELogLevel getEffectiveLevel() const;
/**
* Calls all targets in the hierarchy to write the message.
*
* @param record The log record to write.
*/
inline void callTargets(const LogRecord & record) const;
/**
* Gets all log targets attached to this logger.
*
* @return all log targets as a list
*/
inline std::list<ILogTarget *> getTargets() const;
/** The domain of the logger. */
// Data members
CLoggerDomain domain;
/** A reference to the parent logger. */
CGLogger * parent;
/** The log level of the logger. */
ELogLevel::ELogLevel level;
/** A list of log targets. */
std::list<ILogTarget *> targets;
/** The shared mutex for providing synchronous thread-safe access to the logger. */
mutable boost::shared_mutex mx;
/** The unique mutex for providing thread-safe get logger access. */
static boost::mutex smx;
};
//extern CLogger * logGlobal;

View File

@ -20,12 +20,12 @@ struct LogRecord;
class DLL_LINKAGE ILogTarget : public boost::noncopyable
{
public:
virtual ~ILogTarget() { };
/**
* Writes a log record.
*
* @param record The log record to write.
*/
virtual void write(const LogRecord & record) = 0;
virtual ~ILogTarget() { };
};

View File

@ -18,9 +18,6 @@
*/
struct DLL_LINKAGE LogRecord
{
/**
* Constructor.
*/
LogRecord(const CLoggerDomain & domain, ELogLevel::ELogLevel level, const std::string & message)
: domain(domain), level(level), message(message), timeStamp(boost::posix_time::second_clock::local_time()), threadId(boost::this_thread::get_id())
{