Commit b66ff827 authored by Julien Wintz's avatar Julien Wintz
Browse files

Towards hander implementations for logging layer.

parent 174aa408
......@@ -20,11 +20,14 @@ project(dtkLog)
set(${PROJECT_NAME}_HEADERS
dtkLog
dtkLog.h
dtkLogger.h
dtkLogger_p.h)
dtkLogger_p.h
dtkLoggerHandlers.h)
set(${PROJECT_NAME}_SOURCES
dtkLogger.cpp)
dtkLogger.cpp
dtkLoggerHandlers.cpp)
## #################################################################
## Build rules
......
#include "dtkLog.h"
#include "dtkLogger.h"
#include "dtkLogger_p.h"
#include "dtkLoggerHandlers.h"
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtCore>
namespace dtkLog {
enum HandlerFlag {
Console = 0x00,
File = 0x01
};
Q_DECLARE_FLAGS(HandlerFlags, HandlerFlag);
Q_DECLARE_OPERATORS_FOR_FLAGS(HandlerFlags);
};
//
// dtkLog.h ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkLog.h"
#include "dtkLoggerHandlers.h"
#include <iostream>
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
namespace dtkLogPrivate {
void installFileHandler(void);
void uninstallFileHandler(void);
void handler(QtMsgType type, const QMessageLogContext &context, const QString &message);
};
namespace dtkLogPrivate {
QFile file;
dtkLog::HandlerFlags flags;
};
namespace dtkLogPrivate {
void installFileHandler(void)
{
file.setFileName(QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() + "/dtk.log");
file.open(QIODevice::WriteOnly);
}
void uninstallFileHandler(void)
{
file.close();
}
void handler(QtMsgType type, const QMessageLogContext &context, const QString &message)
{
std::cerr << qPrintable(Q_FUNC_INFO);
}
};
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
void dtkInstallLoggerHandler(dtkLog::HandlerFlags flags)
{
dtkLogPrivate::flags = flags;
if (dtkLogPrivate::flags & dtkLog::File)
dtkLogPrivate::installFileHandler();
qInstallMessageHandler(dtkLogPrivate::handler);
}
void dtkUninstallLoggerHandler()
{
if (dtkLogPrivate::flags & dtkLog::File)
dtkLogPrivate::uninstallFileHandler();
qInstallMessageHandler(0);
}
//
// dtkLoggerHandlers.cpp ends here
......@@ -3,6 +3,7 @@
//
// Commentary:
//
//
......@@ -14,13 +15,13 @@
#pragma once
namespace dtkLog {
enum HandlerFlag {
#include "dtkLog"
};
#include <QtCore>
#include <QtDebug>
};
void dtkInstallLoggerHandler(dtkLog::HandlerFlags);
void dtkUninstallLoggerHandler(void);
//
// dtkLoggerHandlers.h ends here
......@@ -12,6 +12,7 @@
##
### Code:
add_subdirectory(dtkLog)
add_subdirectory(dtkMeta)
add_subdirectory(dtkMath)
......
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkLogTest)
## #################################################################
## Input
## #################################################################
set(${PROJECT_NAME}_HEADERS_MOC
dtkLoggerHandlersTest.h)
set(${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_HEADERS_MOC})
set(${PROJECT_NAME}_SOURCES
dtkLoggerHandlersTest.cpp)
## ###################################################################
## Input - introspected
## ###################################################################
create_test_sourcelist(
${PROJECT_NAME}_SOURCES_TST
${PROJECT_NAME}.cpp
${${PROJECT_NAME}_SOURCES})
## ###################################################################
## Build rules
## ###################################################################
add_executable(${PROJECT_NAME}
${${PROJECT_NAME}_SOURCES_TST}
${${PROJECT_NAME}_SOURCES})
## ###################################################################
## Link rules
## ###################################################################
qt5_use_modules(${PROJECT_NAME} Core)
qt5_use_modules(${PROJECT_NAME} Test)
target_link_libraries(${PROJECT_NAME} dtkLog)
## ###################################################################
## Test rules
## ###################################################################
add_test(dtkLogTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/dtkLogTest dtkLogTest)
######################################################################
### CMakeLists.txt ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkLoggerHandlersTest.h"
#include <dtkLog>
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
dtkLoggerHandlersTestCase::dtkLoggerHandlersTestCase(void)
{
}
dtkLoggerHandlersTestCase::~dtkLoggerHandlersTestCase(void)
{
}
void dtkLoggerHandlersTestCase::initTestCase(void)
{
dtkInstallLoggerHandler(dtkLog::File);
}
void dtkLoggerHandlersTestCase::init(void)
{
}
void dtkLoggerHandlersTestCase::testLoggerHandlers(void)
{
}
void dtkLoggerHandlersTestCase::cleanup(void)
{
}
void dtkLoggerHandlersTestCase::cleanupTestCase(void)
{
dtkUninstallLoggerHandler();
}
DTKTEST_MAIN_NOGUI(dtkLoggerHandlersTest, dtkLoggerHandlersTestCase)
//
// dtkLoggerHandlersTest.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkTest>
class dtkLoggerHandlersTestCase : public QObject
{
Q_OBJECT
public:
dtkLoggerHandlersTestCase(void);
virtual ~dtkLoggerHandlersTestCase(void);
private slots:
void initTestCase(void);
void init(void);
private slots:
void testLoggerHandlers(void);
private slots:
void cleanupTestCase(void);
void cleanup(void);
};
//
// dtkLoggerHandlersTest.h ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment