Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5231: Extract logging interface to ilogwriter.h
- Loading branch information
1 parent
7ad8d69
commit 5f4e64b
Showing
14 changed files
with
104 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace applog | ||
{ | ||
|
||
enum ELogLevel | ||
{ | ||
SYS_VERBOSE = 0, | ||
SYS_STANDARD, | ||
SYS_WARNING, | ||
SYS_ERROR, | ||
SYS_NUM_LOGLEVELS, | ||
}; | ||
|
||
/** | ||
* greebo: A LogDevice is a class which is able to take log output. | ||
* | ||
* Examples of LogDevices are the Console and the DarkRadiant logfile. | ||
* Note: Use the LogWriter::attach() method to register a class for logging. | ||
*/ | ||
class ILogDevice | ||
{ | ||
public: | ||
virtual ~ILogDevice() {} | ||
|
||
/** | ||
* greebo: This method gets called by the ILogWriter with | ||
* a log string as argument. | ||
*/ | ||
virtual void writeLog(const std::string& outputStr, ELogLevel level) = 0; | ||
}; | ||
|
||
/** | ||
* Central logging hub, dispatching any incoming log messages | ||
* to all attached ILogDevices. | ||
*/ | ||
class ILogWriter | ||
{ | ||
public: | ||
virtual ~ILogWriter() | ||
{} | ||
|
||
/** | ||
* greebo: Writes the given buffer p with the given length to the | ||
* various output devices (i.e. Console and Log file). | ||
*/ | ||
virtual void write(const char* p, std::size_t length, ELogLevel level) = 0; | ||
|
||
/** | ||
* greebo: Use these methods to attach/detach a log device from the | ||
* writer class. After attaching a device, all log output | ||
* will be written to it. | ||
*/ | ||
virtual void attach(ILogDevice* device) = 0; | ||
virtual void detach(ILogDevice* device) = 0; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
#ifndef _STRING_LOG_DEVICE_H_ | ||
#define _STRING_LOG_DEVICE_H_ | ||
#pragma once | ||
|
||
#include <sstream> | ||
#include "LogDevice.h" | ||
#include <memory> | ||
#include "ilogwriter.h" | ||
|
||
namespace applog { | ||
|
||
class StringLogDevice; | ||
typedef std::shared_ptr<StringLogDevice> StringLogDevicePtr; | ||
namespace applog | ||
{ | ||
|
||
/** | ||
* greebo: A StringLogDevice is a class which logs into a local string buffer. | ||
*/ | ||
class StringLogDevice : | ||
public LogDevice | ||
public ILogDevice | ||
{ | ||
private: | ||
std::ostringstream _errorStream; | ||
std::ostringstream _warningStream; | ||
std::ostringstream _logStream; | ||
|
||
public: | ||
typedef std::shared_ptr<StringLogDevice> Ptr; | ||
|
||
StringLogDevice(); | ||
~StringLogDevice(); | ||
|
||
/** | ||
* greebo: This method gets called by the Writer with | ||
* a logging string as argument. | ||
*/ | ||
void writeLog(const std::string& outputStr, ELogLevel level); | ||
void writeLog(const std::string& outputStr, ELogLevel level) override; | ||
|
||
// Returns the temporary buffer for the given level | ||
std::string getString(ELogLevel level); | ||
|
||
// Destroys the static instance | ||
static void destroy(); | ||
|
||
static StringLogDevicePtr& InstancePtr(); | ||
static Ptr& InstancePtr(); | ||
}; | ||
|
||
} // namespace applog | ||
|
||
#endif /* _STRING_LOG_DEVICE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters