Last change
on this file since 1097 was 1096, checked in by s10k, 7 years ago |
Added zlib, quazip, basicxmlsyntaxhighlighter, conditionalsemaphore and linenumberdisplay libraries. zlib and quazip are pre-compiled, but you can compile them yourself, just delete the dll files (or equivalent binary files to your OS)
|
File size:
1.6 KB
|
Rev | Line | |
---|
[1096] | 1 | #pragma once
|
---|
| 2 | #include <plog/Appenders/IAppender.h>
|
---|
| 3 | #include <plog/Util.h>
|
---|
| 4 | #include <vector>
|
---|
| 5 |
|
---|
| 6 | #ifndef PLOG_DEFAULT_INSTANCE
|
---|
| 7 | # define PLOG_DEFAULT_INSTANCE 0
|
---|
| 8 | #endif
|
---|
| 9 |
|
---|
| 10 | namespace plog
|
---|
| 11 | {
|
---|
| 12 | template<int instance>
|
---|
| 13 | class Logger : public util::Singleton<Logger<instance> >, public IAppender
|
---|
| 14 | {
|
---|
| 15 | public:
|
---|
| 16 | Logger(Severity maxSeverity = none) : m_maxSeverity(maxSeverity)
|
---|
| 17 | {
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | Logger& addAppender(IAppender* appender)
|
---|
| 21 | {
|
---|
| 22 | assert(appender != this);
|
---|
| 23 | m_appenders.push_back(appender);
|
---|
| 24 | return *this;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | Severity getMaxSeverity() const
|
---|
| 28 | {
|
---|
| 29 | return m_maxSeverity;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | void setMaxSeverity(Severity severity)
|
---|
| 33 | {
|
---|
| 34 | m_maxSeverity = severity;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | bool checkSeverity(Severity severity) const
|
---|
| 38 | {
|
---|
| 39 | return severity <= m_maxSeverity;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | virtual void write(const Record& record)
|
---|
| 43 | {
|
---|
| 44 | if (checkSeverity(record.getSeverity()))
|
---|
| 45 | {
|
---|
| 46 | *this += record;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | void operator+=(const Record& record)
|
---|
| 51 | {
|
---|
| 52 | for (std::vector<IAppender*>::iterator it = m_appenders.begin(); it != m_appenders.end(); ++it)
|
---|
| 53 | {
|
---|
| 54 | (*it)->write(record);
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | private:
|
---|
| 59 | Severity m_maxSeverity;
|
---|
| 60 | std::vector<IAppender*> m_appenders;
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | template<int instance>
|
---|
| 64 | inline Logger<instance>* get()
|
---|
| 65 | {
|
---|
| 66 | return Logger<instance>::getInstance();
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | inline Logger<PLOG_DEFAULT_INSTANCE>* get()
|
---|
| 70 | {
|
---|
| 71 | return Logger<PLOG_DEFAULT_INSTANCE>::getInstance();
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.