Remove obsolete logging framework

This changes removes classes of the obsolete logging frame work and
all its references. It was not used anywhere, but included in several
headers.
Had to add header QDateTime in some places, which was not correctly
included and now missing.

refs #90
This commit is contained in:
Roland Winklmeier
2014-01-18 20:09:03 +01:00
parent 32cfb5c10b
commit 08302c23bb
22 changed files with 3 additions and 1200 deletions

View File

@@ -15,6 +15,7 @@
#include "avheading.h"
#include "pqspeed.h"
#include "valueobject.h"
#include <QDateTime>
namespace BlackMisc
{

View File

@@ -3,7 +3,6 @@
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/
#include "blackmisc/debug.h"
#include "blackmisc/context.h"
#include <QFileInfo>
#include <QCoreApplication>

View File

@@ -6,7 +6,6 @@
#ifndef BLACKMISC_CONTEXT_H
#define BLACKMISC_CONTEXT_H
#include "blackmisc/debug.h"
#include <QMetaType>
#include <QObject>
#include <QMap>
@@ -161,25 +160,6 @@ namespace BlackMisc
* \return
*/
virtual const QString &getApplicationName() const = 0;
/*!
* Return the CDebug object.
* \return
* \throw std::logic_error The requested object is not present.
*/
CDebug &getDebug()
{
return getObject<CDebug>();
}
/*!
* Set the CDebug object.
* \param debug
*/
void setDebug(CDebug &debug)
{
setObject(debug);
}
};
/*!

View File

@@ -1,140 +0,0 @@
#include "blackmisc/debug.h"
#include "blackmisc/log.h"
#include "blackmisc/display.h"
#include "blackmisc/context.h"
#include <QDir>
#include <QCoreApplication>
namespace BlackMisc
{
CDebug::CDebug()
: m_isInitialized(false), m_errorLog(NULL), m_warningLog(NULL),
m_infoLog(NULL), m_debugLog(NULL)
{
}
void CDebug::create(const char * /** logPath **/, bool logInFile, bool eraseLastLog)
{
if (!m_isInitialized)
{
setErrorLog(new CLog(IContext::getInstance(), CLog::eError));
setWarningLog(new CLog(IContext::getInstance(), CLog::eWarning));
setInfoLog(new CLog(IContext::getInstance(), CLog::eInfo));
setDebugLog(new CLog(IContext::getInstance(), CLog::eDebug));
stdDisplayer = new CStdDisplay("DEFAULT_SD");
if (logInFile)
{
QDir fileinfo(m_logPath);
QString fn;
if (!m_logPath.isEmpty())
{
m_logPath = fileinfo.absolutePath();
fn += m_logPath;
}
else
{
}
fileDisplayer = new CFileDisplay("", true, "DEFAULT_FD");
fileDisplayer = new CFileDisplay("", eraseLastLog, "DEFAULT_FD");
}
init(true);
m_isInitialized = true;
}
}
void CDebug::init(bool logInFile)
{
m_debugLog->attachDisplay(stdDisplayer);
m_infoLog->attachDisplay(stdDisplayer);
m_warningLog->attachDisplay(stdDisplayer);
m_errorLog->attachDisplay(stdDisplayer);
if (logInFile)
{
m_debugLog->attachDisplay(fileDisplayer);
m_infoLog->attachDisplay(fileDisplayer);
m_warningLog->attachDisplay(fileDisplayer);
m_errorLog->attachDisplay(fileDisplayer);
}
}
QString CDebug::getLogDirectory()
{
return m_logPath;
}
CLog *CDebug::getErrorLog()
{
return m_errorLog;
}
void CDebug::setErrorLog(CLog *errorLog)
{
m_errorLog = errorLog;
}
CLog *CDebug::getWarningLog()
{
return m_warningLog;
}
void CDebug::setWarningLog(CLog *warningLog)
{
m_warningLog = warningLog;
}
CLog *CDebug::getInfoLog()
{
return m_infoLog;
}
void CDebug::setInfoLog(CLog *infoLog)
{
m_infoLog = infoLog;
}
CLog *CDebug::getDebugLog()
{
return m_debugLog;
}
void CDebug::setDebugLog(CLog *debugLog)
{
m_debugLog = debugLog;
}
CLogMessage CDebug::blackInfo(int line, const char *fileName, const char *methodName)
{
create();
m_infoLog->setLogInformation(line, fileName, methodName);
return CLogMessage(*this, CLog::eInfo);
}
CLogMessage CDebug::blackWarning(int line, const char *fileName, const char *methodName)
{
create();
m_warningLog->setLogInformation(line, fileName, methodName);
return CLogMessage(*this, CLog::eWarning);
}
CLogMessage CDebug::blackDebug(int line, const char *fileName, const char *methodName)
{
create();
m_debugLog->setLogInformation(line, fileName, methodName);
return CLogMessage(*this, CLog::eDebug);
}
CLogMessage CDebug::blackError(int line, const char *fileName, const char *methodName)
{
create();
m_errorLog->setLogInformation(line, fileName, methodName);
return CLogMessage(*this, CLog::eError);
}
} // namespace BlackMisc

View File

@@ -1,122 +0,0 @@
//! Copyright (C) 2013 Roland Winklmeier
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/
#ifndef BLACKMISC_DEBUG_H
#define BLACKMISC_DEBUG_H
#include "blackmisc/log.h"
#include "blackmisc/display.h"
#include "blackmisc/logmessage.h"
// This header contains debug macros
namespace BlackMisc
{
//! class CDebug
/*! This class implements the logging of the library. It holds a list of displays
takes care of any additional information needed, e.g. timestamps, filename etc.
To use the logging use the default displayer or implement your own one and
register it with this class.
*/
class CDebug : public QObject
{
Q_OBJECT
public:
CDebug();
// internal use only
void create(const char *logPath = "", bool logInFile = true, bool eraseLastLog = false);
// init Debug
void init(bool logInFile);
/// Do not call this, unless you know what you're trying to do (it kills debug)!
void destroy() {}
void changeLogDirectory(const QString &dir) { Q_UNUSED(dir); }
QString getLogDirectory();
//! Pure virtual method returns the pointer to the global error log object
/*!
\return Pointer to CLog object
*/
CLog *getErrorLog();
//! Pure virtual function to set the global error log object
/*!
\param Pointer to CLog object
*/
void setErrorLog(CLog *errorLog);
//! Pure virtual method returns the pointer to the global warning log object
/*!
\return Pointer to CLog object
*/
CLog *getWarningLog();
//! Pure virtual function to set the global warning log object
/*!
\param Pointer to CLog object
*/
void setWarningLog(CLog *warningLog);
//! Pure virtual method returns the pointer to the global info log object
/*!
\return Pointer to CLog object
*/
CLog *getInfoLog();
//! Pure virtual function to set the global info log object
/*!
\param Pointer to CLog object
*/
void setInfoLog(CLog *infoLog);
//! Pure virtual method returns the pointer to the global debug log object
/*!
\return Pointer to CLog object
*/
CLog *getDebugLog();
//! Pure virtual function to set the global debug log object
/*!
\param Pointer to CLog object
*/
void setDebugLog(CLog *debugLog);
CLogMessage blackInfo(int line, const char *fileName, const char *methodName);
CLogMessage blackWarning(int line, const char *fileName, const char *methodName);
CLogMessage blackDebug(int line, const char *fileName, const char *methodName);
CLogMessage blackError(int line, const char *fileName, const char *methodName);
private:
bool m_isInitialized;
CStdDisplay *stdDisplayer;
CFileDisplay *fileDisplayer;
QString m_logPath;
CLog *m_errorLog;
CLog *m_warningLog;
CLog *m_infoLog;
CLog *m_debugLog;
};
#define bInfo(CONTEXT) ( (CONTEXT).getDebug().blackInfo(__LINE__, __FILE__, __FUNCTION__ ) )
#define bWarning(CONTEXT) ( (CONTEXT).getDebug().blackWarning(__LINE__, __FILE__, __FUNCTION__ ) )
#define bDebug(CONTEXT) ( (CONTEXT).getDebug().blackDebug(__LINE__, __FILE__, __FUNCTION__ ) )
#define bError(CONTEXT) ( (CONTEXT).getDebug().blackError(__LINE__, __FILE__, __FUNCTION__ ) )
#define bAppInfo bInfo(BlackMisc::IContext::getInstance())
#define bAppWarning bWarning(BlackMisc::IContext::getInstance())
#define bAppDebug bDebug(BlackMisc::IContext::getInstance())
#define bAppError bError(BlackMisc::IContext::getInstance())
} // namespace BlackMisc
#endif //BLACKMISC_DEBUG_H

View File

@@ -1,248 +0,0 @@
//! Copyright (C) 2013 Roland Winklmeier
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/
#include "blackmisc/display.h"
#include "blackmisc/context.h"
#include <QTextStream>
#include <QFileInfo>
#include <errno.h>
namespace BlackMisc
{
static const char *LogTypeToString[7] =
{ "", "Error", "Warning", "Info", "Debug", "Assert", "Unknown" };
ILogDisplay::ILogDisplay(const QString &displayName)
{
m_mutex = new QMutex ();
DisplayName = displayName;
}
ILogDisplay::~ILogDisplay()
{
delete m_mutex;
}
const char *ILogDisplay::logTypeToString (CLog::TLogType logType)
{
if (logType < CLog::eOff || logType >= CLog::eLast)
return "Not defined";
return LogTypeToString[logType];
}
QString ILogDisplay::currentDateToString ()
{
QDateTime currentDateTime = QDateTime::currentDateTime();
QString format("yyyy-MM-dd hh:mm:ss");
return currentDateTime.toString(format);
}
QString ILogDisplay::dateToString (const QDateTime &time)
{
QString format("yyyy-MM-dd hh:mm:ss");
return time.toString(format);
}
QString ILogDisplay::headLine ()
{
QString header = QString("\n Logging started at %1\n").arg(currentDateToString());
return header;
}
/*
* Display the string where it does.
*/
void ILogDisplay::print (const CLog::SLogInformation &logInformation, const QString &message)
{
m_mutex->lock();
doPrint( logInformation, message );
m_mutex->unlock();
}
void CStdDisplay::doPrint (const CLog::SLogInformation &logInformation, const QString &message)
{
bool needSpace = false;
QString line;
if (logInformation.m_logType != CLog::eOff)
{
line += logTypeToString(logInformation.m_logType);
needSpace = true;
}
// Write thread identifier
if ( logInformation.m_threadId != 0 )
{
if (needSpace) { line += " "; needSpace = false; }
line += QString("%1").arg(logInformation.m_threadId);
}
if (logInformation.m_sourceFile != NULL)
{
if (needSpace) { line += " "; needSpace = false; }
line += QFileInfo (logInformation.m_sourceFile).fileName();
needSpace = true;
}
if (logInformation.m_line != -1)
{
if (needSpace) { line += " "; needSpace = false; }
line += QString("%1").arg(logInformation.m_line);
needSpace = true;
}
if (logInformation.m_methodName != NULL)
{
if (needSpace) { line += " "; needSpace = false; }
line += logInformation.m_methodName;
needSpace = true;
}
if (logInformation.m_applicationName != NULL)
{
if (needSpace) { line += " "; needSpace = false; }
line += logInformation.m_applicationName;
needSpace = true;
}
if (needSpace) { line += " : "; needSpace = false; }
line += message;
QTextStream out(stdout);
out << line;
}
CFileDisplay::CFileDisplay (const QString &filename, bool eraseLastLog, const QString &displayName) :
ILogDisplay (displayName), m_needHeader(true)
{
setParam (filename, eraseLastLog);
}
CFileDisplay::CFileDisplay () :
ILogDisplay (""), m_needHeader(true)
{
}
CFileDisplay::~CFileDisplay ()
{
if ( m_file->handle() != -1 )
{
m_file->close();
}
delete m_file;
}
void CFileDisplay::setParam (const QString &filename, bool eraseLastLog)
{
m_fileName = filename;
m_file = new QFile(m_fileName);
if (eraseLastLog)
{
// Erase all the derived log files
int i = 0;
bool fileExist = true;
while (fileExist)
{
QFileInfo info(m_fileName);
QString fileToDelete = info.absolutePath() + "/" + info.baseName() + QString("%1").arg(i, 3, 10, QChar('0')) + info.completeSuffix();
if ( QFile::exists(fileToDelete) )
QFile(fileToDelete).remove();
else
fileExist = false;
i++;
}
}
if ( m_file->handle() != -1 )
{
m_file->close();
}
}
void CFileDisplay::doPrint (const CLog::SLogInformation &logInformation, const QString &message)
{
bool needSpace = false;
QString line;
// if the filename is not set, don't log
if ( m_fileName.isEmpty() ) return;
if (logInformation.m_dateTime.isValid())
{
line += dateToString(logInformation.m_dateTime);
needSpace = true;
}
if (logInformation.m_logType != CLog::eOff)
{
if (needSpace) { line += " "; needSpace = false; }
line += logTypeToString(logInformation.m_logType);
needSpace = true;
}
if (!logInformation.m_applicationName.isEmpty())
{
if (needSpace) { line += " "; needSpace = false; }
line += logInformation.m_applicationName;
needSpace = true;
}
if (logInformation.m_sourceFile != NULL)
{
if (needSpace) { line += " "; needSpace = false; }
line += QFileInfo (logInformation.m_sourceFile).fileName();
needSpace = true;
}
if (logInformation.m_line != -1)
{
if (needSpace) { line += " "; needSpace = false; }
line += QString("%1").arg(logInformation.m_line);
needSpace = true;
}
if (logInformation.m_methodName != NULL)
{
if (needSpace) { line += " "; needSpace = false; }
line += logInformation.m_methodName;
needSpace = true;
}
if (needSpace) { line += " : "; needSpace = false; }
line += message;
// Try to open the file if the handle is invalid
if (m_file->handle() == -1)
{
if ( !m_file->open(QIODevice::WriteOnly) ) {
// suppress warning about unsafe strerror
printf ("Can't open log file '%s': %d (%s)\n", m_fileName.toLatin1().constData(), errno, ""/*strerror(errno)*/);
}
}
if (m_file->handle() != -1)
{
QTextStream out(m_file);
if (m_needHeader)
{
const QString hs = headLine();
out << hs;
m_needHeader = false;
}
if(!line.isEmpty())
out << line;
}
}
}

View File

@@ -1,94 +0,0 @@
//! Copyright (C) 2013 Roland Winklmeier
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/
#ifndef DISPLAY_H
#define DISPLAY_H
#include "blackmisc/log.h"
#include <QFile>
#include <QMutex>
namespace BlackMisc
{
class ILogDisplay
{
public:
/// Constructor
ILogDisplay(const QString &displayName );
/// Destructor
virtual ~ILogDisplay();
/// Display the string where it does.
void print( const CLog::SLogInformation &logInformation, const QString &message );
/// This is the identifier for a displayer, it is used to find or remove a displayer
QString DisplayName;
protected:
/// Method to implement in the derived class
virtual void doPrint(const CLog::SLogInformation &logInformation, const QString &message) = 0;
// Return the header string with date (for the first line of the log)
static QString headLine ();
public:
/// Convert log type to string
static const char *logTypeToString (CLog::TLogType logType);
/// Convert the current date to human string
static QString currentDateToString ();
/// Convert date to "2000/01/14 10:05:17" string
static QString dateToString (const QDateTime &time);
private:
QMutex *m_mutex;
};
class CStdDisplay : virtual public ILogDisplay
{
public:
CStdDisplay ( const QString &displayerName = QString("")) : ILogDisplay (displayerName) {}
protected:
/// Display the string to stdout and OutputDebugString on Windows
virtual void doPrint (const CLog::SLogInformation &logInformation, const QString &message);
};
class CFileDisplay : virtual public ILogDisplay
{
public:
/// Constructor
CFileDisplay (const QString &filename, bool eraseLastLog = false, const QString &displayName = "");
CFileDisplay ();
~CFileDisplay ();
/// Set Parameter of the displayer if not set at the ctor time
void setParam (const QString &filename, bool eraseLastLog = false);
protected:
/// Put the string into the file.
virtual void doPrint (const CLog::SLogInformation &logInformation, const QString &message);
private:
QString m_fileName;
QFile *m_file;
bool m_needHeader;
};
} // BlackMisc
#endif // DISPLAY_H

View File

@@ -1,228 +0,0 @@
//! Copyright (C) 2013 Roland Winklmeier
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/
#ifndef UNICODE
#define UNICODE
#endif
#include "blackmisc/log.h"
#include "blackmisc/display.h"
#include "blackmisc/debug.h"
#include "blackmisc/context.h"
#include <QTextStream>
#include <QFileInfo>
#include <QtGlobal>
//TODO do we still need these platform includes here?
#ifdef Q_OS_WIN
# ifndef NOMINMAX
# define NOMINMAX
# include <process.h>
# include <windows.h>
# endif
#else
# include <unistd.h>
#endif
namespace BlackMisc
{
CLog::CLog(IContext &context, TLogType logType) : m_context(context), m_logType(logType)
{
}
CLog::~CLog(void)
{
}
void CLog::printWithNewLine(QString &message)
{
//! If we have no displays, we have nothing to do.
if (hasNoDisplays())
{
return;
}
QChar newLine = '\n';
//! We should print the message with a new line. So check
//! if one is already there. If not append it.
if (!message.endsWith(newLine, Qt::CaseInsensitive))
message.append(newLine);
printString(message);
}
void CLog::print(QString &message)
{
//! If we have no displays, we have nothing to do.
if (hasNoDisplays())
{
return;
}
printString(message);
}
void CLog::printString(QString &message)
{
QString logDisplay;
//! Just in case, lets set the default name
m_context.setDefaultApplicationName();
//! If the current line is empty, then put some information as
//! the prefix.
//! Be aware: This information must be set by the \sa setLogInformation()
//! before.
if (m_logLine.isEmpty())
{
m_logInformation.m_dateTime = QDateTime::currentDateTime();
m_logInformation.m_logType = m_logType;
m_logInformation.m_applicationName = m_context.getApplicationName();
m_logInformation.m_threadId = 0; //getThreadId();
m_logInformation.m_sourceFile = m_sourceFile;
m_logInformation.m_line = m_line;
m_logInformation.m_methodName = m_methodName;
m_logLine = message;
}
else
{
m_logLine += message;
}
//! If this is not the end of the line, we are done for now.
if (! message.contains('\n'))
{
return;
}
for (TLogDisplayList::iterator it = m_logDisplays.begin(); it != m_logDisplays.end(); ++it)
{
(*it)->print(m_logInformation, m_logLine);
}
//! Reset everything for the next line
m_logLine.clear();
resetLogInformation();
}
void CLog::attachDisplay(ILogDisplay *display)
{
//! Display must be a valid pointer
if (display == NULL)
{
printf("Trying to add a NULL pointer\n");
return;
}
//! Check if it is already attached
if (!m_logDisplays.contains(display))
{
m_logDisplays.push_back(display);
}
else
{
bWarning(m_context) << "Couldn't attach the display - already in the list!";
}
}
ILogDisplay *CLog::getDisplay(const QString &displayName)
{
//! Must be a valid name
if (displayName.isEmpty())
{
bWarning(m_context) << "Cannot return a display with empty name!";
return NULL;
}
TLogDisplayList::const_iterator it;
//! Loop through the list and find the candidate
for (it = m_logDisplays.constBegin(); it != m_logDisplays.constEnd(); ++it)
{
//! Does it have the desired name?
if ((*it)->DisplayName == displayName)
{
return *it;
}
}
return NULL;
}
void CLog::dettachDisplay(ILogDisplay *logDisplay)
{
//! Must be a valid pointer
if (logDisplay == NULL)
{
bWarning(m_context) << "Cannot remove a NULL displayer!";
return;
}
//! We should have only one, but just in case.
m_logDisplays.removeAll(logDisplay);
}
void CLog::dettachDisplay(const QString &displayName)
{
//! Must be a valid name
if (displayName.isEmpty())
{
bWarning(m_context) << "Cannot remove displayer with empty name!";
return;
}
TLogDisplayList::iterator it;
for (it = m_logDisplays.begin(); it != m_logDisplays.end();)
{
if ((*it)->DisplayName == displayName)
{
it = m_logDisplays.erase(it);
}
else
{
++it;
}
}
}
bool CLog::isAttached(ILogDisplay *logDisplay) const
{
return m_logDisplays.contains(logDisplay);
}
void CLog::setLogInformation(int line, const char *sourceFile, const char *methodName)
{
//! We have to make sure, we at least one display.
if (!hasNoDisplays())
{
m_mutex.lock();
m_posSet++;
m_sourceFile = sourceFile;
m_line = line;
m_methodName = methodName;
}
}
void CLog::resetLogInformation()
{
//! It should be impossible that this gets called, withoud
//! having a attached display.
Q_ASSERT(!hasNoDisplays());
if (m_posSet > 0)
{
m_sourceFile = NULL;
m_line = -1;
m_methodName = NULL;
m_posSet--;
m_mutex.unlock();
}
}
} // namespace BlackMisc

View File

@@ -1,194 +0,0 @@
//! Copyright (C) 2013 Roland Winklmeier
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/
#ifndef BLACKMISC_LOG_H
#define BLACKMISC_LOG_H
#include <QMutex>
#include <QList>
#include <QString>
#include <QDateTime>
namespace BlackMisc
{
class ILogDisplay;
class IContext;
//! Logging class
/*! This class implements the logging of the library. It holds a list of displays
takes care of any additional information needed, e.g. timestamps, filename etc.
To use the logging use the default displayer or implement your own one and
register it with this class.
*/
class CLog
{
public:
//! Logging type.
/*! This enum holds all different available log types. */
enum TLogType
{
eOff = 0,
eError,
eWarning,
eInfo,
eDebug,
eLast
};
//! SLogParameter
/*!
This structs capsulates all information needed to output a log line.
*/
struct SLogInformation
{
SLogInformation() : m_dateTime(), m_logType(CLog::eOff), m_applicationName(), m_threadId(0), m_sourceFile(NULL), m_line(-1), m_methodName(NULL) {}
QDateTime m_dateTime;
TLogType m_logType;
QString m_applicationName;
quint32 m_threadId;
const char *m_sourceFile;
qint32 m_line;
const char *m_methodName;
};
CLog(IContext &context, TLogType logType = eOff);
//! CLog destructor.
virtual ~CLog(void);
/*!
* Display
*/
//! This method adds a Displayer to the Log object
/*! CLog does not own the pointer. It is the callers responsibility
to allocate the displayer and remove it after using. */
/*!
\param display A pointer to a display.
\sa ILogDisplay
*/
void attachDisplay(BlackMisc::ILogDisplay *display);
//! This method returns the pointer to a registered display.
/*!
\return display A pointer to a display.
*/
ILogDisplay *getDisplay(const QString &displayName);
//! Removes a display
/*!
\param logDisplay Pointer to the display.
*/
void dettachDisplay(ILogDisplay *logDisplay);
//! Removes a display by its name.
/*!
\param displayName Name of the display.
*/
void dettachDisplay(const QString &displayName);
//! Checks if the displayer is added
/*!
\param logDisplay Pointer to a display.
\return Returns true if display is attached, otherwise false.
*/
bool isAttached(ILogDisplay *logDisplay) const;
//! Checks if the object has any attached displays
/*!
\return Returns true if no display is attached, otherwise false.
*/
bool hasNoDisplays() const { return m_logDisplays.empty(); }
//! Sets any additional information as prefix to the log message
/*!
\param fileName This is the name of the corresponding source file.
\param methodName This is the name of calling method.
*/
void setLogInformation(int line, const char *fileName, const char *methodName = NULL);
//! Prints the message and adds an new line character at the end
/*!
\param message Message string, which has to be logged
*/
void printWithNewLine(QString &message);
//! Prints the message as is and appends no additional characters
/*!
\param message Message string, which has to be logged
*/
void print(QString &message);
void printString(QString &message);
protected:
/// Display a string in decorated form to all attached displayers.
void displayString(const char *str);
/// Symetric to setPosition(). Automatically called by display...(). Do not call if noDisplayer().
void resetLogInformation();
//! Context
IContext &m_context;
//! Logging Type.
/*!
Specifies which logging type should be used.
Possible are: Error, Warning, Info, Debug and Assert.
*/
TLogType m_logType;
//! Source file name.
/*!
Specifies the name of the source file, log message was called from.
*/
const char *m_sourceFile;
//! Code line.
/*!
Specifies the line in the source file, log message was called from.
*/
qint32 m_line;
//! Method name.
/*!
Specifies the method in the source file, log message was called from.
*/
const char *m_methodName;
/*!
\typedef TLogDisplayerMap
QList container holding pointers to ILogDisplay objects
\sa ArrayList::GetEnumerator, \sa List::GetEnumerator
*/
typedef QList<ILogDisplay *> TLogDisplayList;
//! List of all attached displays.
TLogDisplayList m_logDisplays;
//! Mutex object
/*!
This makes our class thread safe.
*/
QMutex m_mutex;
//! Position
quint32 m_posSet;
//! Log message string
/*!
This variable is used, if a log line consists of two or more
calls. The first ones are then stored temporary in this variable
until one message ends with a line feed.
*/
QString m_logLine;
SLogInformation m_logInformation;
};
} // namespace BlackMisc
#endif //BLACKMISC_LOG_H

View File

@@ -1,53 +0,0 @@
#include "blackmisc/logmessage.h"
#include "blackmisc/debug.h"
namespace BlackMisc
{
CLogMessage::LogStream::LogStream(CLog::TLogType type)
: output(&buffer, QIODevice::WriteOnly),
type(type), needSpace(true), enableOutput(true), reference(1)
{}
CLogMessage::CLogMessage(CDebug &debug_, CLog::TLogType type)
: logStream(new LogStream(type)), debug(debug_)
{
}
CLogMessage::CLogMessage(const CLogMessage &other)
: logStream(other.logStream), debug(other.debug)
{
++logStream->reference;
}
CLogMessage::~CLogMessage()
{
if (!--logStream->reference)
{
if (logStream->enableOutput)
{
switch (logStream->type)
{
case CLog::eWarning:
debug.getWarningLog()->printWithNewLine(logStream->buffer);
break;
case CLog::eInfo:
debug.getInfoLog()->printWithNewLine(logStream->buffer);
break;
case CLog::eDebug:
debug.getDebugLog()->printWithNewLine(logStream->buffer);
break;
case CLog::eError:
default:
debug.getErrorLog()->printWithNewLine(logStream->buffer);
break;
}
}
delete logStream;
}
}
} // namespace Blackib

View File

@@ -1,74 +0,0 @@
//! Copyright (C) 2013 Roland Winklmeier
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/
#ifndef LOGMESSAGE_H
#define LOGMESSAGE_H
#include "blackmisc/log.h"
#include <QTextStream>
namespace BlackMisc
{
class CDebug;
class CLogMessage
{
struct LogStream
{
//! Constructor
LogStream(CLog::TLogType type);
QTextStream output;
//! Message Buffer
QString buffer;
//! Logging type
CLog::TLogType type;
bool needSpace;
bool enableOutput;
//! Reference count
quint32 reference;
} *logStream;
CDebug &debug;
public:
CLogMessage(CDebug &debug_, CLog::TLogType type);
CLogMessage(const CLogMessage &other);
~CLogMessage();
inline CLogMessage &maybeSpace() { if (logStream->needSpace) logStream->output << ' '; return *this; }
inline CLogMessage &operator<<(QChar t) { logStream->output << '\'' << t << '\''; return maybeSpace(); }
inline CLogMessage &operator<<(bool t) { logStream->output << (t ? "true" : "false"); return maybeSpace(); }
inline CLogMessage &operator<<(char t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(signed short t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(unsigned short t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(signed int t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(unsigned int t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(signed long t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(unsigned long t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(qint64 t)
{ logStream->output << QString::number(t); return maybeSpace(); }
inline CLogMessage &operator<<(quint64 t)
{ logStream->output << QString::number(t); return maybeSpace(); }
inline CLogMessage &operator<<(float t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(double t) { logStream->output << t; return maybeSpace(); }
inline CLogMessage &operator<<(const char *t) { logStream->output << QString::fromLatin1(t); return maybeSpace(); }
inline CLogMessage &operator<<(const QString &t) { logStream->output << '\"' << t << '\"'; return maybeSpace(); }
inline CLogMessage &operator<<(const QByteArray &t) { logStream->output << '\"' << t << '\"'; return maybeSpace(); }
inline CLogMessage &operator<<(QTextStreamManipulator m)
{ logStream->output << m; return *this; }
};
} // BlackMisc
#endif // guard

View File

@@ -13,6 +13,7 @@
#include "pqfrequency.h"
#include "avcallsign.h"
#include "valueobject.h"
#include <QDateTime>
namespace BlackMisc
{

View File

@@ -7,7 +7,6 @@
#define BLACKMISC_PQBASE_H
#include "blackmisc/valueobject.h"
#include "blackmisc/debug.h"
#include "blackmisc/mathematics.h"
#include <QCoreApplication>
#include <QtDBus/QDBusArgument>

View File

@@ -9,7 +9,6 @@
#include "blackmisc/pqbase.h"
#include "blackmisc/pqunits.h"
#include "blackmisc/mathematics.h"
#include "blackmisc/debug.h"
#include <QtDBus/QDBusMetaType>
#include <QtGlobal>
#include <QString>

View File

@@ -2,6 +2,7 @@
#define BLACKMISC_STATUSMESSAGE_H
#include "valueobject.h"
#include <QDateTime>
namespace BlackMisc
{

View File

@@ -1,7 +1,6 @@
#ifndef BLACKMISC_VALUEOBJECT_H
#define BLACKMISC_VALUEOBJECT_H
#include "blackmisc/debug.h"
#include <QtDBus/QDBusMetaType>
#include <QString>
#include <QtGlobal>
@@ -69,18 +68,6 @@ namespace BlackMisc
return stream;
}
/*!
* \brief Stream operator << for log messages
* \param log
* \param uc
* \return
*/
friend CLogMessage operator<<(CLogMessage log, const CValueObject &uc)
{
log << uc.stringForStreaming();
return log;
}
/*!
* \brief Stream operator << for std::cout
* \param ostr

View File

@@ -14,7 +14,6 @@
#include <QtCore/qglobal.h>
#include <blackmisc/debug.h>
#include "driver_fsx.h"
extern "C"