Adds initial intermediate qt6 porting state
This commit is contained in:
11247 files changed
+1891537
No files matched your search
@@ -0,0 +1,58 @@
|
||||
|
||||
FIND_PACKAGE(Log4Qt)
|
||||
|
||||
# Sourcen
|
||||
SET(NGLLogger_SRCS
|
||||
MurmurHash2.cpp
|
||||
MurmurHash2.h
|
||||
INGLLogger.h
|
||||
|
||||
NGLLogger_export.h
|
||||
NGLLoggerBootstrap.cpp
|
||||
NGLLoggerBootstrap.h
|
||||
NGLLogger.cpp
|
||||
NGLLogger.h
|
||||
)
|
||||
|
||||
# Header
|
||||
SET(NGLLogger_HDRS
|
||||
)
|
||||
|
||||
# Make sure NGLLogger.h compiles ..
|
||||
ADD_DEFINITIONS(-DBUILDING_NGLLOGGER)
|
||||
NGL_ADD_LIBRARY(ALL NGLLogger SHARED ${NGLLogger_SRCS} ${NGLLogger_HDRS})
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(NGLLogger
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
|
||||
# Export headers for other modules building in the same tree (e.g., TetraIF)
|
||||
# Ensure NGLLogger target provides include paths so consumers can include <NGLLogger/INGLLogger.h>
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(NGLLogger
|
||||
PRIVATE
|
||||
$<IF:$<BOOL:${Log4Qt_FOUND}>,Log4Qt::log4qt,>
|
||||
PUBLIC
|
||||
Qt5::Core
|
||||
)
|
||||
|
||||
NGL_INSTALL_TARGET(NGLLogger)
|
||||
|
||||
#
|
||||
# test_ngllogger
|
||||
#
|
||||
IF(BUILD_TESTING AND TARGET NGLLogger AND Log4Qt_FOUND)
|
||||
ADD_EXECUTABLE(test_ngllogger test_ngllogger.cpp)
|
||||
TARGET_LINK_LIBRARIES(test_ngllogger NGLLogger)
|
||||
TARGET_LINK_LIBRARIES(test_ngllogger
|
||||
Log4Qt::log4qt
|
||||
ngltools
|
||||
)
|
||||
ADD_TEST(NAME test_ngllogger COMMAND $<TARGET_FILE:test_ngllogger>)
|
||||
ELSE()
|
||||
MESSAGE(STATUS "Log4Qt not found; skipping test_ngllogger")
|
||||
ENDIF()
|
||||
|
||||
|
||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/log4cxx.props ${CMAKE_BINARY_DIR}/log4cxx.props COPYONLY)
|
||||
+306
@@ -0,0 +1,306 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <QString>
|
||||
#include <QPointF>
|
||||
#include <QSize>
|
||||
#include <QRect>
|
||||
#include <QRectF>
|
||||
#include <QList>
|
||||
#include "NGLLogger_export.h"
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
|
||||
enum class LogLevel
|
||||
{
|
||||
Undefined = 0,
|
||||
Trace = 64,
|
||||
Debug = 96,
|
||||
Info = 128,
|
||||
Warning = 150,
|
||||
Error = 182,
|
||||
Fatal = 214,
|
||||
};
|
||||
|
||||
class LogStreamHelper
|
||||
{
|
||||
public:
|
||||
inline LogStreamHelper(INGLLogger &logger, LogLevel level, const char *const file, int line, const char *const function)
|
||||
: m_logger(logger)
|
||||
, m_level(level)
|
||||
, m_line(line)
|
||||
, m_file(file)
|
||||
, m_func(function)
|
||||
{}
|
||||
inline ~LogStreamHelper();
|
||||
|
||||
template<typename T>
|
||||
inline LogStreamHelper &operator<<(const T &val);
|
||||
|
||||
private:
|
||||
std::ostringstream m_buffer;
|
||||
NGL::INGLLogger &m_logger;
|
||||
const LogLevel m_level;
|
||||
const int m_line;
|
||||
const char *const m_file;
|
||||
const char *const m_func;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class INGLLogger
|
||||
{
|
||||
public:
|
||||
INGLLogger(const INGLLogger &) = delete;
|
||||
INGLLogger &operator=(const INGLLogger &) = delete;
|
||||
INGLLogger() = default;
|
||||
virtual ~INGLLogger() = default;
|
||||
|
||||
using String = std::string;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual INGLLogger &getNGLLogger(const char *fullqualifiedname) = 0;
|
||||
virtual INGLLogger &getNGLLogger(const std::string &fullqualifiedname) = 0;
|
||||
|
||||
|
||||
|
||||
virtual bool isTraceEnabled() const = 0;
|
||||
virtual bool isDebugEnabled() const = 0;
|
||||
virtual bool isInfoEnabled() const = 0;
|
||||
virtual bool isWarningEnabled() const = 0;
|
||||
virtual bool isErrorEnabled() const = 0;
|
||||
virtual bool isFatalEnabled() const = 0;
|
||||
virtual bool isLevelEnabled(LogLevel level) const = 0;
|
||||
|
||||
|
||||
|
||||
virtual void log(LogLevel level, const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
|
||||
|
||||
virtual void logTrace(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
|
||||
virtual void logDebug(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
|
||||
virtual void logInfo(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
|
||||
virtual void logWarning(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
|
||||
virtual void logError(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
|
||||
virtual void logFatal(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) = 0;
|
||||
|
||||
|
||||
virtual void logStartup(const char *file, int line, const char *function = nullptr) = 0;
|
||||
|
||||
virtual void logShutdown(const char *file, int line, const char *function = nullptr) = 0;
|
||||
|
||||
|
||||
virtual std::string getLoggerName() const = 0;
|
||||
|
||||
virtual void setNoSpace(bool bNoSpace) = 0;
|
||||
virtual bool noSpace() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
inline LogStreamHelper::~LogStreamHelper()
|
||||
{
|
||||
m_logger.log(m_level, m_buffer.str(), m_file, m_line, m_func);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline LogStreamHelper &LogStreamHelper::operator<<(const T &val)
|
||||
{
|
||||
m_buffer << val;
|
||||
if (!m_logger.noSpace())
|
||||
m_buffer << " ";
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QByteArray &str)
|
||||
{
|
||||
stream << std::string(str.data(), str.size());
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &stream,
|
||||
const QPointF &value)
|
||||
{
|
||||
stream << "QPointF(" << QString::number(value.x(), 'f', 6).toStdString() << "#" << QString::number(value.y(), 'f', 6).toStdString() << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline std::ostream &operator<< (std::ostream &stream,
|
||||
const QPoint &value)
|
||||
{
|
||||
stream << "QPoint(" << value.x() << "#" << value.y() << ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline std::ostream &operator<< (std::ostream &stream,
|
||||
const QSize &value)
|
||||
{
|
||||
stream << "QSize(w=" << value.width() << ";h=" << value.height() << ")";
|
||||
return stream;
|
||||
}
|
||||
inline std::ostream &operator<< (std::ostream &stream,
|
||||
const QSizeF &value)
|
||||
{
|
||||
stream << "QSize(w="
|
||||
<< QString::number(value.width(), 'f', 6).toStdString() << ";h="
|
||||
<< QString::number(value.height(), 'f', 6).toStdString()
|
||||
<< ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
inline std::ostream &operator<< (std::ostream &stream,
|
||||
const QRect &value)
|
||||
{
|
||||
stream << "QRect(center=" << value.center()
|
||||
<< " w=" << value.width()
|
||||
<< ";h=" << value.height()
|
||||
<< " bottomLeft=" << value.bottomLeft()
|
||||
<< " topRight=" << value.topRight()
|
||||
<< ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline std::ostream &operator<< (std::ostream &stream,
|
||||
const QRectF &value)
|
||||
{
|
||||
stream << "QRectF(center=" << value.center()
|
||||
<< " w=" << QString::number(value.width(), 'f', 3).toStdString()
|
||||
<< ";h=" << QString::number(value.height(), 'f', 3).toStdString()
|
||||
<< " bottomLeft=" << value.bottomLeft()
|
||||
<< " topRight=" << value.topRight()
|
||||
<< ")";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline std::ostream &operator<< (std::ostream &stream,
|
||||
const QList<int> &value)
|
||||
{
|
||||
stream << "QList<int>(" << value.size() << "): ";
|
||||
for (int i : value)
|
||||
stream << i << ";";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
inline std::ostream &operator<< (std::ostream &stream,
|
||||
const QList<QPointF> &value)
|
||||
{
|
||||
stream << "QList<QPointF>(" << value.size() << "): ";
|
||||
for (const QPointF &item : value)
|
||||
stream << item << ";";
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &stream, const QString &str)
|
||||
{
|
||||
return stream << str.toUtf8();
|
||||
}
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
namespace NGLLoggerHelper
|
||||
{
|
||||
NGLLOGGER_EXPORT void hexDumpHelper(NGL::INGLLogger &logger,
|
||||
NGL::LogLevel level,
|
||||
const void *a_data,
|
||||
const unsigned int a_size);
|
||||
inline void hexDumpHelper(NGL::INGLLogger &logger,
|
||||
NGL::LogLevel level,
|
||||
const QByteArray &data)
|
||||
{
|
||||
return hexDumpHelper(logger, level, data.data(), data.size());
|
||||
}
|
||||
}
|
||||
|
||||
NGLLOGGER_EXPORT NGL::INGLLogger& getMemoryLogger();
|
||||
NGLLOGGER_EXPORT std::string getMemoryData();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define LOGFUNCTION Q_FUNC_INFO
|
||||
|
||||
|
||||
#define NOTICE_LOG(logger) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Info, __FILE__,__LINE__, Q_FUNC_INFO)
|
||||
|
||||
#ifdef LTS_DEBUG
|
||||
#define TRACE_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isTraceEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Trace, __FILE__,__LINE__, Q_FUNC_INFO)
|
||||
#else
|
||||
#define TRACE_LOG(logger) \
|
||||
for ( ; false; ) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Trace, __FILE__,__LINE__, Q_FUNC_INFO)
|
||||
#endif
|
||||
|
||||
#define DEBUG_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isDebugEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Debug, __FILE__,__LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define INFO_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isInfoEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Info, __FILE__,__LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define WARNING_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isWarningEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Warning, __FILE__,__LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define ERROR_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isErrorEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Error, __FILE__,__LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define FATAL_LOG(logger) \
|
||||
for (bool log_level_enabled = (logger).isFatalEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(logger, NGL::LogLevel::Fatal, __FILE__,__LINE__, Q_FUNC_INFO)
|
||||
|
||||
#define STARTUP_LOG(logger) { (logger).logStartup(__FILE__, __LINE__, Q_FUNC_INFO); }
|
||||
#define SHUTDOWN_LOG(logger) { (logger).logShutdown(__FILE__, __LINE__, Q_FUNC_INFO); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define MEMORY_LOG() \
|
||||
for (bool log_level_enabled = (NGL::getMemoryLogger()).isInfoEnabled(); log_level_enabled; log_level_enabled = false) \
|
||||
NGL::LogStreamHelper(NGL::getMemoryLogger(), NGL::LogLevel::Info, __FILE__,__LINE__, Q_FUNC_INFO) << NGL::getMemoryData()
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "MurmurHash2.h"
|
||||
#include <QtCore/qcompilerdetection.h>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed )
|
||||
{
|
||||
|
||||
|
||||
|
||||
const unsigned int m = 0x5bd1e995;
|
||||
const int r = 24;
|
||||
|
||||
|
||||
|
||||
unsigned int h = seed ^ len;
|
||||
|
||||
|
||||
|
||||
const unsigned char * data = (const unsigned char *)key;
|
||||
|
||||
while(len >= 4)
|
||||
{
|
||||
unsigned int k = *(reinterpret_cast<const unsigned int *>(data));
|
||||
|
||||
k *= m;
|
||||
k ^= k >> r;
|
||||
k *= m;
|
||||
|
||||
h *= m;
|
||||
h ^= k;
|
||||
|
||||
data += 4;
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch(len)
|
||||
{
|
||||
case 3: h ^= data[2] << 16;
|
||||
Q_FALLTHROUGH();
|
||||
case 2: h ^= data[1] << 8;
|
||||
Q_FALLTHROUGH();
|
||||
case 1: h ^= data[0];
|
||||
h *= m;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
h ^= h >> 13;
|
||||
h *= m;
|
||||
h ^= h >> 15;
|
||||
|
||||
return h;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed = 0 );
|
||||
}
|
||||
@@ -0,0 +1,446 @@
|
||||
|
||||
|
||||
|
||||
#include "NGLLogger.h"
|
||||
#include "MurmurHash2.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include <log4qt/logger.h>
|
||||
#include <log4qt/logmanager.h>
|
||||
#include <log4qt/loggerrepository.h>
|
||||
#include <log4qt/propertyconfigurator.h>
|
||||
#include <log4qt/rollingfileappender.h>
|
||||
#include <log4qt/helpers/configuratorhelper.h>
|
||||
#include <log4qt/helpers/properties.h>
|
||||
#include <log4qt/helpers/factory.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
void LtsRollingFileAppender::setLtsLogfileName(const QString <sLogfileName)
|
||||
{
|
||||
m_ltsLogfileName = ltsLogfileName;
|
||||
}
|
||||
|
||||
void LtsRollingFileAppender::activateOptions()
|
||||
{
|
||||
if (!m_ltsLogfileName.isEmpty())
|
||||
setFile(m_ltsLogfileName);
|
||||
Log4Qt::RollingFileAppender::activateOptions();
|
||||
}
|
||||
|
||||
QString LtsRollingFileAppender::m_ltsLogfileName;
|
||||
static Log4Qt::Appender *createLtsRollingFileAppender()
|
||||
{
|
||||
auto ret = new LtsRollingFileAppender;
|
||||
ret->setAppendFile(true);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class CleanupHelper final
|
||||
{
|
||||
public:
|
||||
CleanupHelper() = default;
|
||||
~CleanupHelper();
|
||||
std::mutex &getLoggerMapMutex();
|
||||
|
||||
std::unordered_map<unsigned int, NGL::NGLLogger *> m_loggermap;
|
||||
protected:
|
||||
std::mutex m_loggermapmutex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::NGLLogger *NGL::NGLLogger::rootlogger_ptr = nullptr;
|
||||
|
||||
NGL::CleanupHelper NGL::NGLLogger::s_cleanup;
|
||||
|
||||
|
||||
|
||||
|
||||
CleanupHelper::~CleanupHelper()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_loggermapmutex);
|
||||
|
||||
for (auto it : m_loggermap)
|
||||
delete it.second;
|
||||
m_loggermap.clear();
|
||||
|
||||
delete NGL::NGLLogger::rootlogger_ptr;
|
||||
NGL::NGLLogger::rootlogger_ptr = nullptr;
|
||||
}
|
||||
|
||||
std::mutex &CleanupHelper::getLoggerMapMutex()
|
||||
{
|
||||
return m_loggermapmutex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::NGLLogger::NGLLogger(const std::string &fullqualifiedname)
|
||||
: name(fullqualifiedname)
|
||||
, currentLevel(LogLevel::Undefined)
|
||||
, m_bNoSpace(true)
|
||||
{
|
||||
if (!fullqualifiedname.empty())
|
||||
{
|
||||
logger_ptr = Log4Qt::LogManager::loggerRepository()->logger(QString::fromStdString(name));
|
||||
s_cleanup.m_loggermap[MurmurHash2(fullqualifiedname.c_str(), fullqualifiedname.size())] = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger_ptr = Log4Qt::LogManager::loggerRepository()->rootLogger();
|
||||
|
||||
}
|
||||
|
||||
|
||||
configChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger &NGL::NGLLogger::getNGLLogger(const char *fullqualifiedname)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_cleanup.getLoggerMapMutex());
|
||||
auto it = s_cleanup.m_loggermap.find(MurmurHash2(fullqualifiedname, strlen(fullqualifiedname)));
|
||||
if (it != s_cleanup.m_loggermap.end())
|
||||
return *(*it).second;
|
||||
|
||||
return *(new NGLLogger(fullqualifiedname));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger &NGL::NGLLogger::getNGLLogger(const std::string &fullqualifiedname)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_cleanup.getLoggerMapMutex());
|
||||
auto it = s_cleanup.m_loggermap.find(MurmurHash2(fullqualifiedname.c_str(), fullqualifiedname.size()));
|
||||
if (it != s_cleanup.m_loggermap.end())
|
||||
return *(*it).second;
|
||||
|
||||
return *(new NGLLogger(fullqualifiedname));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::log(LogLevel level, const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
logger_ptr->logWithLocation(static_cast<Log4Qt::Level::Value>(level), file, line, function, QString::fromStdString(message));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logTrace(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Trace)
|
||||
log(LogLevel::Trace, message, file, line, function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logDebug(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Debug)
|
||||
log(LogLevel::Debug, message, file, line, function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logInfo(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Info)
|
||||
log(LogLevel::Info, message, file, line, function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logWarning(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Warning)
|
||||
log(LogLevel::Warning, message, file, line, function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logError(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
if (currentLevel >= LogLevel::Error)
|
||||
log(LogLevel::Error, message, file, line, function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logFatal(const INGLLogger::String &message, const char *file, int line, const char *function)
|
||||
{
|
||||
log(LogLevel::Fatal, message, file, line, function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef LTS_VERSION_MAJOR
|
||||
#define LTS_VERSION_MAJOR "undefined"
|
||||
#endif
|
||||
#ifndef LTS_VERSION_MINOR
|
||||
#define LTS_VERSION_MINOR "undefined"
|
||||
#endif
|
||||
#ifndef LTS_VERSION_PATCH
|
||||
#define LTS_VERSION_PATCH "undefined"
|
||||
#endif
|
||||
#ifndef LTS_VERSION_DATE
|
||||
#define LTS_VERSION_DATE "undefined"
|
||||
#endif
|
||||
#ifndef JENKINS_BUILD_NUMBER
|
||||
#define JENKINS_BUILD_NUMBER "unknown"
|
||||
#endif
|
||||
static const char ver_major[] = LTS_VERSION_MAJOR;
|
||||
static const char ver_minor[] = LTS_VERSION_MINOR;
|
||||
static const char ver_patch[] = LTS_VERSION_PATCH;
|
||||
static const char ver_date[] = LTS_VERSION_DATE;
|
||||
static const char ver_jenkins[] = JENKINS_BUILD_NUMBER;
|
||||
|
||||
void NGL::NGLLogger::logStartup(const char *file, int line, const char *function)
|
||||
{
|
||||
log(LogLevel::Info, QStringLiteral("Application is started (%1.%2-%3 rev%4 from %5)")
|
||||
.arg(QString::fromLatin1(ver_major),
|
||||
QString::fromLatin1(ver_minor),
|
||||
QString::fromLatin1(ver_jenkins),
|
||||
QString::fromLatin1(ver_patch),
|
||||
QString::fromLatin1(ver_date)).toUtf8().constData(), file, line, function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void NGL::NGLLogger::logShutdown(const char *file, int line, const char *function)
|
||||
{
|
||||
log(LogLevel::Info, QStringLiteral("Application is shut down (%1.%2-%3 rev%4 from %5)")
|
||||
.arg(QString::fromLatin1(ver_major),
|
||||
QString::fromLatin1(ver_minor),
|
||||
QString::fromLatin1(ver_jenkins),
|
||||
QString::fromLatin1(ver_patch),
|
||||
QString::fromLatin1(ver_date)).toUtf8().constData(), file, line, function);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::NGLLogger &NGL::NGLLogger::getNGLRootLogger()
|
||||
{
|
||||
if (!rootlogger_ptr) throw NotCreatedError();
|
||||
return *rootlogger_ptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static QString findConfigFile(const QString &configfilename)
|
||||
{
|
||||
if (configfilename.isEmpty())
|
||||
return QString();
|
||||
|
||||
|
||||
QFileInfo fi(configfilename);
|
||||
if (fi.isFile() && fi.isReadable())
|
||||
return fi.absoluteFilePath();
|
||||
|
||||
|
||||
QString p = QCoreApplication::applicationDirPath() + QLatin1Char('/') + configfilename;
|
||||
fi.setFile(p);
|
||||
if (fi.isFile() && fi.isReadable())
|
||||
return fi.absoluteFilePath();
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::NGLLogger &NGL::NGLLogger::createNGLRootLogger(const QString &configfilename,
|
||||
bool ignorealreadycreated,
|
||||
const QString &logOutputName,
|
||||
bool quiet)
|
||||
{
|
||||
if (rootlogger_ptr)
|
||||
{
|
||||
if (!ignorealreadycreated) throw AlreadyCreatedError();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log4Qt::Factory::registerAppender("Lts::RollingFileAppender", createLtsRollingFileAppender);
|
||||
LtsRollingFileAppender::setLtsLogfileName(logOutputName);
|
||||
|
||||
rootlogger_ptr = new NGLLogger(std::string());
|
||||
const QString filename = findConfigFile(configfilename);
|
||||
if (!filename.isEmpty())
|
||||
{
|
||||
Log4Qt::PropertyConfigurator::configureAndWatch(filename);
|
||||
QObject::connect(Log4Qt::ConfiguratorHelper::instance(), &Log4Qt::ConfiguratorHelper::configurationFileChanged,
|
||||
[]() { configurationFileChanged(); });
|
||||
const auto l = Log4Qt::ConfiguratorHelper::instance()->configureError();
|
||||
for (const auto &t : l)
|
||||
std::cerr << t.message().toUtf8().data() << std::endl;
|
||||
if (!l.isEmpty())
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!quiet)
|
||||
std::cerr << "Could not find log4cxx configuration file " << configfilename << std::endl
|
||||
<< "Using default logging to stdout" << std::endl;
|
||||
|
||||
|
||||
Log4Qt::Properties props;
|
||||
props.setProperty(QLatin1String("log4j.rootLogger"),
|
||||
QLatin1String("WARN, stdout"));
|
||||
props.setProperty(QLatin1String("log4j.appender.stdout"),
|
||||
QLatin1String("org.apache.log4j.ConsoleAppender"));
|
||||
props.setProperty(QLatin1String("log4j.appender.stdout.layout"),
|
||||
QLatin1String("org.apache.log4j.PatternLayout"));
|
||||
props.setProperty(QLatin1String("log4j.appender.stdout.layout.ConversionPattern"),
|
||||
QLatin1String("%d %-5p %c |#| %m (%.50F:%L) %n"));
|
||||
Log4Qt::PropertyConfigurator::configure(props);
|
||||
}
|
||||
rootlogger_ptr->configChanged();
|
||||
}
|
||||
return *rootlogger_ptr;
|
||||
}
|
||||
|
||||
void NGL::NGLLogger::configurationFileChanged()
|
||||
{
|
||||
for (auto ptr : s_cleanup.m_loggermap)
|
||||
ptr.second->configChanged();
|
||||
}
|
||||
|
||||
void NGL::NGLLogger::configChanged()
|
||||
{
|
||||
if (logger_ptr->isTraceEnabled())
|
||||
currentLevel = LogLevel::Trace;
|
||||
else if (logger_ptr->isDebugEnabled())
|
||||
currentLevel = LogLevel::Debug;
|
||||
else if (logger_ptr->isInfoEnabled())
|
||||
currentLevel = LogLevel::Info;
|
||||
else if (logger_ptr->isWarnEnabled())
|
||||
currentLevel = LogLevel::Warning;
|
||||
else if (logger_ptr->isErrorEnabled())
|
||||
currentLevel = LogLevel::Error;
|
||||
else
|
||||
currentLevel = LogLevel::Fatal;
|
||||
}
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
namespace NGLLoggerHelper
|
||||
{
|
||||
|
||||
void hexDumpHelper(NGL::INGLLogger &logger, NGL::LogLevel level,
|
||||
const void *a_data, const unsigned int a_size)
|
||||
{
|
||||
if (!logger.isLevelEnabled(level) || !a_data)
|
||||
return;
|
||||
|
||||
unsigned char *data = (unsigned char *)a_data;
|
||||
QByteArray baBuf;
|
||||
for (unsigned int i = 0; i < a_size; i++)
|
||||
{
|
||||
if (0 == (i % 8))
|
||||
baBuf = QByteArray::number(i, 16).rightJustified(8, '0').toUpper();
|
||||
baBuf += " " + QByteArray::number(data[i], 16).rightJustified(2, '0').toUpper();
|
||||
if (7 == (i % 8))
|
||||
logger.log(level, baBuf.constData(), __FILE__, __LINE__);
|
||||
}
|
||||
if (a_size % 8)
|
||||
logger.log(level, baBuf.constData(), __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
NGL::INGLLogger& getMemoryLogger()
|
||||
{
|
||||
try
|
||||
{
|
||||
return NGLLogger::getNGLRootLogger().getNGLLogger("memorystate");
|
||||
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int parseLine(char* line){
|
||||
|
||||
int i = strlen(line);
|
||||
const char* p = line;
|
||||
while (*p <'0' || *p > '9') p++;
|
||||
line[i-3] = '\0';
|
||||
i = atoi(p);
|
||||
return i;
|
||||
}
|
||||
|
||||
int getMemoryValue()
|
||||
{
|
||||
|
||||
FILE* file = fopen("/proc/self/status", "r");
|
||||
int result = -1;
|
||||
char line[128];
|
||||
|
||||
while (fgets(line, 128, file) != NULL){
|
||||
|
||||
if (strncmp(line, "VmRSS:", 6) == 0){
|
||||
result = parseLine(line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string getMemoryData()
|
||||
{
|
||||
return QStringLiteral("VmRSS: %1 kB #").arg(QString::number(getMemoryValue())).toStdString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef BUILDING_NGLLOGGER
|
||||
#error Do not include me outside NGLLogger library - only use INGLLogger.h!
|
||||
#endif
|
||||
|
||||
#include "INGLLogger.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <log4qt/logger.h>
|
||||
#include <log4qt/rollingfileappender.h>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
class CleanupHelper;
|
||||
|
||||
class LtsRollingFileAppender final : public Log4Qt::RollingFileAppender
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using Log4Qt::RollingFileAppender::RollingFileAppender;
|
||||
static void setLtsLogfileName(const QString <sLogfileName);
|
||||
void activateOptions() override;
|
||||
private:
|
||||
static QString m_ltsLogfileName;
|
||||
};
|
||||
|
||||
class NGLLogger final : public INGLLogger
|
||||
{
|
||||
explicit NGLLogger(const std::string &fullqualifiedname);
|
||||
public:
|
||||
|
||||
class NotCreatedError {};
|
||||
class AlreadyCreatedError {};
|
||||
|
||||
INGLLogger &getNGLLogger(const char *fullqualifiedname) override;
|
||||
INGLLogger &getNGLLogger(const std::string &fullqualifiedname) override;
|
||||
|
||||
inline bool isTraceEnabled() const override { return currentLevel <= LogLevel::Trace; }
|
||||
inline bool isDebugEnabled() const override { return currentLevel <= LogLevel::Debug; }
|
||||
inline bool isInfoEnabled() const override { return currentLevel <= LogLevel::Info; }
|
||||
inline bool isWarningEnabled() const override { return currentLevel <= LogLevel::Warning; }
|
||||
inline bool isErrorEnabled() const override { return currentLevel <= LogLevel::Error; }
|
||||
inline bool isFatalEnabled() const override { return currentLevel <= LogLevel::Fatal; }
|
||||
inline bool isLevelEnabled(LogLevel level) const override { return currentLevel <= level; }
|
||||
|
||||
void log(LogLevel level, const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logTrace(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logDebug(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logInfo(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logWarning(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logError(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
void logFatal(const INGLLogger::String &message, const char *file = nullptr, int line = -1, const char *function = nullptr) override;
|
||||
|
||||
void logStartup(const char *file, int line, const char *function = nullptr) override;
|
||||
void logShutdown(const char *file, int line, const char *function = nullptr) override;
|
||||
|
||||
inline void setNoSpace(bool bNoSpace) override { m_bNoSpace = bNoSpace; }
|
||||
inline bool noSpace() const override { return m_bNoSpace; }
|
||||
|
||||
inline std::string getLoggerName() const override { return name; }
|
||||
|
||||
static NGLLogger &getNGLRootLogger();
|
||||
static NGLLogger &createNGLRootLogger(const QString &configfilename,
|
||||
bool ignorealreadycreated,
|
||||
const QString &logOutputName = QString(),
|
||||
bool quiet = false);
|
||||
|
||||
Log4Qt::Logger *log4qtLogger() { return logger_ptr; }
|
||||
protected:
|
||||
static void configurationFileChanged();
|
||||
void configChanged();
|
||||
|
||||
private:
|
||||
|
||||
Log4Qt::Logger *logger_ptr;
|
||||
const std::string name;
|
||||
LogLevel currentLevel;
|
||||
bool m_bNoSpace;
|
||||
|
||||
static NGLLogger *rootlogger_ptr;
|
||||
|
||||
friend class CleanupHelper;
|
||||
static CleanupHelper s_cleanup;
|
||||
|
||||
friend class XMLWatchdog;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
|
||||
|
||||
#include "NGLLoggerBootstrap.h"
|
||||
#include "NGLLogger.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger & NGL::NGLLoggerBootstrap::getNGLRootLogger()
|
||||
{
|
||||
return NGL::NGLLogger::getNGLRootLogger();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGL::INGLLogger & NGL::NGLLoggerBootstrap::createNGLRootLogger(const QString &configfilename,
|
||||
bool ignorealreadycreated,
|
||||
const QString &logOutputName,
|
||||
bool quiet)
|
||||
{
|
||||
return NGL::NGLLogger::createNGLRootLogger(configfilename, ignorealreadycreated, logOutputName, quiet);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
|
||||
|
||||
#ifndef NGLLOGGERBOOTSTRAP_H
|
||||
#define NGLLOGGERBOOTSTRAP_H
|
||||
|
||||
#include "INGLLogger.h"
|
||||
#include "NGLLogger_export.h"
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
namespace NGLLoggerBootstrap
|
||||
{
|
||||
class AlreadyCreatedError final : public std::exception
|
||||
{
|
||||
const char* what() const noexcept override
|
||||
{
|
||||
return "NGLLogger rootlogger already created!";
|
||||
}
|
||||
};
|
||||
|
||||
class NotCreatedError final : public std::exception
|
||||
{
|
||||
const char* what() const noexcept override
|
||||
{
|
||||
return "NGLLogger rootlogger not yet created!";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
NGLLOGGER_EXPORT INGLLogger &getNGLRootLogger();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NGLLOGGER_EXPORT INGLLogger &createNGLRootLogger(const QString &configfilename,
|
||||
bool ignorealreadycreated,
|
||||
const QString &logOutputName = QString(),
|
||||
bool quiet = false);
|
||||
inline INGLLogger &createNGLRootLogger(const char *configfilename,
|
||||
bool ignorealreadycreated,
|
||||
const QString &logOutputName = QString())
|
||||
{
|
||||
return createNGLRootLogger(QString::fromUtf8(configfilename), ignorealreadycreated, logOutputName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
#ifndef NGLLOGGER_EXPORT_H
|
||||
#define NGLLOGGER_EXPORT_H
|
||||
|
||||
#ifndef NGLLOGGER_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define NGLLOGGER_EXPORT
|
||||
# else
|
||||
# ifdef WIN32
|
||||
# ifdef MAKE_NGLLOGGER_LIB
|
||||
# define NGLLOGGER_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define NGLLOGGER_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define NGLLOGGER_EXPORT __attribute__((visibility("default")))
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
log4j.reset=true
|
||||
log4j.rootLogger=ERROR, stdout
|
||||
|
||||
log4j.logger.Gui=TRACE, console
|
||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.console.layout.ConversionPattern=%p %d %t %c{1} - %F:%L %m%n
|
||||
|
||||
|
||||
log4j.logger.ngs=FATAL, stdout
|
||||
log4j.logger.ngs.Application_1=INFO, file
|
||||
log4j.logger.ngs.Application_2=ERROR
|
||||
log4j.logger.ngs.Application_3=ERROR
|
||||
|
||||
log4j.logger.libsymbol.SymbolTable=WARN, stdout
|
||||
log4j.logger.libsymbol.SymbolReader=WARN, stdout
|
||||
log4j.logger.libngldb=INFO, stdout
|
||||
|
||||
log4j.logger.NGL.main=INFO, stdout, file
|
||||
log4j.logger.NGL.MainWindow=INFO, stdout, file
|
||||
log4j.logger.NGL.zwmsqt=INFO, stdout, file
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=#ngs# %r %p %d %t %c %c{1} - %F:%L %m%n
|
||||
|
||||
log4j.appender.file=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.file.MaxFileSize=1MB
|
||||
log4j.appender.file.MaxBackupIndex=9
|
||||
log4j.appender.file.file=log.out
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=#ngs# %r %p %d %t %c %c{1} - %F:%L %m%n
|
||||
|
||||
log4j.appender.syslog=org.apache.log4j.SyslogAppender
|
||||
log4j.appender.syslog.Threshold=WARN
|
||||
log4j.appender.syslog.SysLogHost=localhost
|
||||
log4j.appender.syslog.Facility=LOCAL7
|
||||
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.syslog.layout.ConversionPattern= %-4r %-5p %c %x - %m
|
||||
log4j.appender.syslog.LevelRangeFilter.AcceptOnMatch=true
|
||||
log4j.appender.syslog.LevelRangeFilter.LevelMin=INFO
|
||||
log4j.appender.syslog.LevelRangeFilter.LevelMax=FATAL
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "INGLLogger.h"
|
||||
#include "NGLLoggerBootstrap.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
NGL::NGLLoggerBootstrap::createNGLRootLogger("log4cxx.props", false);
|
||||
|
||||
NGL::INGLLogger &l = NGL::NGLLoggerBootstrap::getNGLRootLogger(). getNGLLogger( "Gui" );
|
||||
|
||||
STARTUP_LOG(l);
|
||||
SHUTDOWN_LOG(l);
|
||||
NOTICE_LOG(l) << "Gui - NOTICE";
|
||||
TRACE_LOG(l) << "Gui - TRACE";
|
||||
DEBUG_LOG(l) << "Gui - DEBUG";
|
||||
INFO_LOG(l) << "Gui - INFO";
|
||||
WARNING_LOG(l) << "Gui - WARNING";
|
||||
ERROR_LOG(l) << "Gui - ERROR";
|
||||
FATAL_LOG(l) << "Gui - FATAL";
|
||||
|
||||
NGL::INGLLogger &l2 = NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger( "Gui.AES" );
|
||||
NOTICE_LOG(l2) << "Gui.AES - NOTICE";
|
||||
TRACE_LOG(l2) << "Gui.AES - TRACE";
|
||||
DEBUG_LOG(l2) << "Gui.AES - DEBUG";
|
||||
INFO_LOG(l2) << "Gui.AES - INFO";
|
||||
WARNING_LOG(l2) << "Gui.AES - WARNING";
|
||||
ERROR_LOG(l2) << "Gui.AES - ERROR";
|
||||
FATAL_LOG(l2) << "Gui.AES - FATAL";
|
||||
SHUTDOWN_LOG(l2)
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user