Added menu item on win32 tray icon to copy the last 1000 lines from

the log to the clipboard.
This commit is contained in:
crs
2003-06-02 20:06:03 +00:00
parent 5a65e36c99
commit 7b58356fc7
16 changed files with 258 additions and 19 deletions

View File

@@ -91,6 +91,10 @@ CLog::~CLog()
index != m_outputters.end(); ++index) {
delete *index;
}
for (COutputterList::iterator index = m_alwaysOutputters.begin();
index != m_alwaysOutputters.end(); ++index) {
delete *index;
}
ARCH->closeMutex(m_mutex);
s_log = NULL;
}
@@ -189,13 +193,18 @@ CLog::printt(const char* file, int line, const char* fmt, ...) const
}
void
CLog::insert(ILogOutputter* outputter)
CLog::insert(ILogOutputter* outputter, bool alwaysAtHead)
{
assert(outputter != NULL);
assert(outputter->getNewline() != NULL);
CLogLock lock(m_mutex);
m_outputters.push_front(outputter);
if (alwaysAtHead) {
m_alwaysOutputters.push_front(outputter);
}
else {
m_outputters.push_front(outputter);
}
int newlineLength = strlen(outputter->getNewline());
if (newlineLength > m_maxNewlineLength) {
m_maxNewlineLength = newlineLength;
@@ -207,15 +216,17 @@ CLog::remove(ILogOutputter* outputter)
{
CLogLock lock(m_mutex);
m_outputters.remove(outputter);
m_alwaysOutputters.remove(outputter);
}
void
CLog::pop_front()
CLog::pop_front(bool alwaysAtHead)
{
CLogLock lock(m_mutex);
if (!m_outputters.empty()) {
delete m_outputters.front();
m_outputters.pop_front();
COutputterList* list = alwaysAtHead ? &m_alwaysOutputters : &m_outputters;
if (!list->empty()) {
delete list->front();
list->pop_front();
}
}
@@ -266,6 +277,22 @@ CLog::output(int priority, char* msg) const
// write to each outputter
CLogLock lock(m_mutex);
for (COutputterList::const_iterator index = m_alwaysOutputters.begin();
index != m_alwaysOutputters.end();
++index) {
// get outputter
ILogOutputter* outputter = *index;
// put an appropriate newline at the end
strcat(msg + g_priorityPad, outputter->getNewline());
// open the outputter
outputter->open(kApplication);
// write message
outputter->write(static_cast<ILogOutputter::ELevel>(priority),
msg + g_maxPriorityLength - n);
}
for (COutputterList::const_iterator index = m_outputters.begin();
index != m_outputters.end(); ++index) {
// get outputter

View File

@@ -61,12 +61,15 @@ public:
true then it also goes to the next outputter, as so on until an
outputter returns false or there are no more outputters. Outputters
still in the outputter list when the log is destroyed will be
deleted.
deleted. If \c alwaysAtHead is true then the outputter is always
called before all outputters with \c alwaysAtHead false and the
return value of the outputter is ignored.
By default, the logger has one outputter installed which writes to
the console.
*/
void insert(ILogOutputter* adopted);
void insert(ILogOutputter* adopted,
bool alwaysAtHead = false);
//! Remove an outputter from the list
/*!
@@ -79,9 +82,10 @@ public:
//! Remove the outputter from the head of the list
/*!
Removes and deletes the outputter at the head of the outputter list.
This does nothing if the outputter list is empty.
This does nothing if the outputter list is empty. Only removes
outputters that were inserted with the matching \c alwaysAtHead.
*/
void pop_front();
void pop_front(bool alwaysAtHead = false);
//! Set the minimum priority filter.
/*!
@@ -132,6 +136,7 @@ private:
CArchMutex m_mutex;
COutputterList m_outputters;
COutputterList m_alwaysOutputters;
int m_maxNewlineLength;
int m_maxPriority;
};

View File

@@ -179,3 +179,60 @@ CSystemLogger::~CSystemLogger()
delete m_stop;
delete m_syslog;
}
//
// CBufferedLogOutputter
//
CBufferedLogOutputter::CBufferedLogOutputter(UInt32 maxBufferSize) :
m_maxBufferSize(maxBufferSize)
{
// do nothing
}
CBufferedLogOutputter::~CBufferedLogOutputter()
{
// do nothing
}
CBufferedLogOutputter::const_iterator
CBufferedLogOutputter::begin() const
{
return m_buffer.begin();
}
CBufferedLogOutputter::const_iterator
CBufferedLogOutputter::end() const
{
return m_buffer.end();
}
void
CBufferedLogOutputter::open(const char*)
{
// do nothing
}
void
CBufferedLogOutputter::close()
{
// remove all elements from the buffer
m_buffer.clear();
}
bool
CBufferedLogOutputter::write(ELevel, const char* message)
{
while (m_buffer.size() >= m_maxBufferSize) {
m_buffer.pop_front();
}
m_buffer.push_back(CString(message));
return true;
}
const char*
CBufferedLogOutputter::getNewline() const
{
return "";
}

View File

@@ -15,7 +15,10 @@
#ifndef LOGOUTPUTTERS_H
#define LOGOUTPUTTERS_H
#include "BasicTypes.h"
#include "ILogOutputter.h"
#include "CString.h"
#include "stddeque.h"
//! Stop traversing log chain outputter
/*!
@@ -86,4 +89,40 @@ private:
ILogOutputter* m_stop;
};
//! Save log history
/*!
This outputter records the last N log messages.
*/
class CBufferedLogOutputter : public ILogOutputter {
private:
typedef std::deque<CString> CBuffer;
public:
typedef CBuffer::const_iterator const_iterator;
CBufferedLogOutputter(UInt32 maxBufferSize);
virtual ~CBufferedLogOutputter();
//! @name accessors
//@{
//! Get start of buffer
const_iterator begin() const;
//! Get end of buffer
const_iterator end() const;
//@}
// ILogOutputter overrides
virtual void open(const char* title);
virtual void close();
virtual bool write(ELevel level, const char* message);
virtual const char* getNewline() const;
private:
UInt32 m_maxBufferSize;
CBuffer m_buffer;
};
#endif

View File

@@ -107,6 +107,10 @@ SOURCE=.\stdbitset.h
# End Source File
# Begin Source File
SOURCE=.\stddeque.h
# End Source File
# Begin Source File
SOURCE=.\stdfstream.h
# End Source File
# Begin Source File

17
lib/common/stddeque.h Normal file
View File

@@ -0,0 +1,17 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stdpre.h"
#include <deque>
#include "stdpost.h"