| 1 | /*
|
|---|
| 2 | * synergy -- mouse and keyboard sharing utility
|
|---|
| 3 | * Copyright (C) 2002 Chris Schoeneman
|
|---|
| 4 | *
|
|---|
| 5 | * This package is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU General Public License
|
|---|
| 7 | * found in the file COPYING that should have accompanied this file.
|
|---|
| 8 | *
|
|---|
| 9 | * This package is distributed in the hope that it will be useful,
|
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | * GNU General Public License for more details.
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | #ifndef LOGOUTPUTTERS_H
|
|---|
| 16 | #define LOGOUTPUTTERS_H
|
|---|
| 17 |
|
|---|
| 18 | #include "BasicTypes.h"
|
|---|
| 19 | #include "ILogOutputter.h"
|
|---|
| 20 | #include "CString.h"
|
|---|
| 21 | #include "stddeque.h"
|
|---|
| 22 |
|
|---|
| 23 | //! Stop traversing log chain outputter
|
|---|
| 24 | /*!
|
|---|
| 25 | This outputter performs no output and returns false from \c write(),
|
|---|
| 26 | causing the logger to stop traversing the outputter chain. Insert
|
|---|
| 27 | this to prevent already inserted outputters from writing.
|
|---|
| 28 | */
|
|---|
| 29 | class CStopLogOutputter : public ILogOutputter {
|
|---|
| 30 | public:
|
|---|
| 31 | CStopLogOutputter();
|
|---|
| 32 | virtual ~CStopLogOutputter();
|
|---|
| 33 |
|
|---|
| 34 | // ILogOutputter overrides
|
|---|
| 35 | virtual void open(const char* title);
|
|---|
| 36 | virtual void close();
|
|---|
| 37 | virtual void show(bool showIfEmpty);
|
|---|
| 38 | virtual bool write(ELevel level, const char* message);
|
|---|
| 39 | virtual const char* getNewline() const;
|
|---|
| 40 | };
|
|---|
| 41 |
|
|---|
| 42 | //! Write log to console
|
|---|
| 43 | /*!
|
|---|
| 44 | This outputter writes output to the console. The level for each
|
|---|
| 45 | message is ignored.
|
|---|
| 46 | */
|
|---|
| 47 | class CConsoleLogOutputter : public ILogOutputter {
|
|---|
| 48 | public:
|
|---|
| 49 | CConsoleLogOutputter();
|
|---|
| 50 | virtual ~CConsoleLogOutputter();
|
|---|
| 51 |
|
|---|
| 52 | // ILogOutputter overrides
|
|---|
| 53 | virtual void open(const char* title);
|
|---|
| 54 | virtual void close();
|
|---|
| 55 | virtual void show(bool showIfEmpty);
|
|---|
| 56 | virtual bool write(ELevel level, const char* message);
|
|---|
| 57 | virtual const char* getNewline() const;
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | //! Write log to system log
|
|---|
| 61 | /*!
|
|---|
| 62 | This outputter writes output to the system log.
|
|---|
| 63 | */
|
|---|
| 64 | class CSystemLogOutputter : public ILogOutputter {
|
|---|
| 65 | public:
|
|---|
| 66 | CSystemLogOutputter();
|
|---|
| 67 | virtual ~CSystemLogOutputter();
|
|---|
| 68 |
|
|---|
| 69 | // ILogOutputter overrides
|
|---|
| 70 | virtual void open(const char* title);
|
|---|
| 71 | virtual void close();
|
|---|
| 72 | virtual void show(bool showIfEmpty);
|
|---|
| 73 | virtual bool write(ELevel level, const char* message);
|
|---|
| 74 | virtual const char* getNewline() const;
|
|---|
| 75 | };
|
|---|
| 76 |
|
|---|
| 77 | //! Write log to system log only
|
|---|
| 78 | /*!
|
|---|
| 79 | Creating an object of this type inserts a CStopLogOutputter followed
|
|---|
| 80 | by a CSystemLogOutputter into CLog. The destructor removes those
|
|---|
| 81 | outputters. Add one of these to any scope that needs to write to
|
|---|
| 82 | the system log (only) and restore the old outputters when exiting
|
|---|
| 83 | the scope.
|
|---|
| 84 | */
|
|---|
| 85 | class CSystemLogger {
|
|---|
| 86 | public:
|
|---|
| 87 | CSystemLogger(const char* title, bool blockConsole);
|
|---|
| 88 | ~CSystemLogger();
|
|---|
| 89 |
|
|---|
| 90 | private:
|
|---|
| 91 | ILogOutputter* m_syslog;
|
|---|
| 92 | ILogOutputter* m_stop;
|
|---|
| 93 | };
|
|---|
| 94 |
|
|---|
| 95 | //! Save log history
|
|---|
| 96 | /*!
|
|---|
| 97 | This outputter records the last N log messages.
|
|---|
| 98 | */
|
|---|
| 99 | class CBufferedLogOutputter : public ILogOutputter {
|
|---|
| 100 | private:
|
|---|
| 101 | typedef std::deque<CString> CBuffer;
|
|---|
| 102 |
|
|---|
| 103 | public:
|
|---|
| 104 | typedef CBuffer::const_iterator const_iterator;
|
|---|
| 105 |
|
|---|
| 106 | CBufferedLogOutputter(UInt32 maxBufferSize);
|
|---|
| 107 | virtual ~CBufferedLogOutputter();
|
|---|
| 108 |
|
|---|
| 109 | //! @name accessors
|
|---|
| 110 | //@{
|
|---|
| 111 |
|
|---|
| 112 | //! Get start of buffer
|
|---|
| 113 | const_iterator begin() const;
|
|---|
| 114 |
|
|---|
| 115 | //! Get end of buffer
|
|---|
| 116 | const_iterator end() const;
|
|---|
| 117 |
|
|---|
| 118 | //@}
|
|---|
| 119 |
|
|---|
| 120 | // ILogOutputter overrides
|
|---|
| 121 | virtual void open(const char* title);
|
|---|
| 122 | virtual void close();
|
|---|
| 123 | virtual void show(bool showIfEmpty);
|
|---|
| 124 | virtual bool write(ELevel level, const char* message);
|
|---|
| 125 | virtual const char* getNewline() const;
|
|---|
| 126 |
|
|---|
| 127 | private:
|
|---|
| 128 | UInt32 m_maxBufferSize;
|
|---|
| 129 | CBuffer m_buffer;
|
|---|
| 130 | };
|
|---|
| 131 |
|
|---|
| 132 | #endif
|
|---|