2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2014-11-02 12:12:05 +00:00
|
|
|
* Copyright (C) 2012 Synergy Si Ltd.
|
2012-09-04 02:09:56 +00:00
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "base/log_outputters.h"
|
|
|
|
#include "base/TMethodJob.h"
|
|
|
|
#include "arch/Arch.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
2014-02-28 12:36:45 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// StopLogOutputter
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
StopLogOutputter::StopLogOutputter()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
StopLogOutputter::~StopLogOutputter()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
StopLogOutputter::open(const char*)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
StopLogOutputter::close()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
StopLogOutputter::show(bool)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-11 13:51:47 +00:00
|
|
|
StopLogOutputter::write(ELevel, const char*)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// ConsoleLogOutputter
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
ConsoleLogOutputter::ConsoleLogOutputter()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
ConsoleLogOutputter::~ConsoleLogOutputter()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
ConsoleLogOutputter::open(const char* title)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
ARCH->openConsole(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
ConsoleLogOutputter::close()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
ARCH->closeConsole();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
ConsoleLogOutputter::show(bool showIfEmpty)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
ARCH->showConsole(showIfEmpty);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-11 13:51:47 +00:00
|
|
|
ConsoleLogOutputter::write(ELevel level, const char* msg)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
ARCH->writeConsole(level, msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
ConsoleLogOutputter::flush()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// SystemLogOutputter
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
SystemLogOutputter::SystemLogOutputter()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
SystemLogOutputter::~SystemLogOutputter()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
SystemLogOutputter::open(const char* title)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
ARCH->openLog(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
SystemLogOutputter::close()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
ARCH->closeLog();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
SystemLogOutputter::show(bool showIfEmpty)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
ARCH->showLog(showIfEmpty);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-11 13:51:47 +00:00
|
|
|
SystemLogOutputter::write(ELevel level, const char* msg)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
ARCH->writeLog(level, msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// SystemLogger
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
SystemLogger::SystemLogger(const char* title, bool blockConsole) :
|
2012-06-10 16:50:54 +00:00
|
|
|
m_stop(NULL)
|
|
|
|
{
|
|
|
|
// redirect log messages
|
|
|
|
if (blockConsole) {
|
2014-11-11 13:51:47 +00:00
|
|
|
m_stop = new StopLogOutputter;
|
2012-06-10 16:50:54 +00:00
|
|
|
CLOG->insert(m_stop);
|
|
|
|
}
|
2014-11-11 13:51:47 +00:00
|
|
|
m_syslog = new SystemLogOutputter;
|
2012-06-10 16:50:54 +00:00
|
|
|
m_syslog->open(title);
|
|
|
|
CLOG->insert(m_syslog);
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
SystemLogger::~SystemLogger()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
CLOG->remove(m_syslog);
|
|
|
|
delete m_syslog;
|
|
|
|
if (m_stop != NULL) {
|
|
|
|
CLOG->remove(m_stop);
|
|
|
|
delete m_stop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// BufferedLogOutputter
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
BufferedLogOutputter::BufferedLogOutputter(UInt32 maxBufferSize) :
|
2012-06-10 16:50:54 +00:00
|
|
|
m_maxBufferSize(maxBufferSize)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
BufferedLogOutputter::~BufferedLogOutputter()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
BufferedLogOutputter::const_iterator
|
|
|
|
BufferedLogOutputter::begin() const
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
return m_buffer.begin();
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
BufferedLogOutputter::const_iterator
|
|
|
|
BufferedLogOutputter::end() const
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
return m_buffer.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
BufferedLogOutputter::open(const char*)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
BufferedLogOutputter::close()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// remove all elements from the buffer
|
|
|
|
m_buffer.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
BufferedLogOutputter::show(bool)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-11 13:51:47 +00:00
|
|
|
BufferedLogOutputter::write(ELevel, const char* message)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
while (m_buffer.size() >= m_maxBufferSize) {
|
|
|
|
m_buffer.pop_front();
|
|
|
|
}
|
2014-11-11 13:51:47 +00:00
|
|
|
m_buffer.push_back(String(message));
|
2012-06-10 16:50:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// FileLogOutputter
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
FileLogOutputter::FileLogOutputter(const char* logFile)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
2014-10-27 14:11:43 +00:00
|
|
|
setLogFilename(logFile);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
FileLogOutputter::~FileLogOutputter()
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-27 14:11:43 +00:00
|
|
|
void
|
2014-11-11 14:50:09 +00:00
|
|
|
FileLogOutputter::setLogFilename(const char* logFile)
|
2014-10-27 14:11:43 +00:00
|
|
|
{
|
|
|
|
assert(logFile != NULL);
|
|
|
|
m_fileName = logFile;
|
|
|
|
}
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
bool
|
2014-11-11 13:51:47 +00:00
|
|
|
FileLogOutputter::write(ELevel level, const char *message)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
|
|
|
std::ofstream m_handle;
|
|
|
|
m_handle.open(m_fileName.c_str(), std::fstream::app);
|
|
|
|
if (m_handle.is_open() && m_handle.fail() != true) {
|
|
|
|
m_handle << message << std::endl;
|
|
|
|
}
|
|
|
|
m_handle.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
FileLogOutputter::open(const char *title) {}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
FileLogOutputter::close() {}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
FileLogOutputter::show(bool showIfEmpty) {}
|
2013-03-15 16:14:43 +00:00
|
|
|
|
|
|
|
//
|
2014-11-11 13:51:47 +00:00
|
|
|
// MesssageBoxLogOutputter
|
2013-03-15 16:14:43 +00:00
|
|
|
//
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
MesssageBoxLogOutputter::MesssageBoxLogOutputter()
|
2013-03-15 16:14:43 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
MesssageBoxLogOutputter::~MesssageBoxLogOutputter()
|
2013-03-15 16:14:43 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
MesssageBoxLogOutputter::open(const char* title)
|
2013-03-15 16:14:43 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
MesssageBoxLogOutputter::close()
|
2013-03-15 16:14:43 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-11 13:51:47 +00:00
|
|
|
MesssageBoxLogOutputter::show(bool showIfEmpty)
|
2013-03-15 16:14:43 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-11 13:51:47 +00:00
|
|
|
MesssageBoxLogOutputter::write(ELevel level, const char* msg)
|
2013-03-15 16:14:43 +00:00
|
|
|
{
|
|
|
|
// don't spam user with messages.
|
|
|
|
if (level > kERROR) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-04 21:57:51 +00:00
|
|
|
#if SYSAPI_WIN32
|
2013-03-15 16:14:43 +00:00
|
|
|
MessageBox(NULL, msg, CLOG->getFilterName(level), MB_OK);
|
2013-04-04 21:57:51 +00:00
|
|
|
#endif
|
|
|
|
|
2013-03-15 16:14:43 +00:00
|
|
|
return true;
|
|
|
|
}
|