Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dtk
dtk
Commits
e88b30f6
Commit
e88b30f6
authored
Mar 01, 2012
by
Julien Wintz
Browse files
Adding logging layer together with an example.
parent
ed076e3e
Changes
16
Hide whitespace changes
Inline
Side-by-side
examples/CMakeLists.txt
View file @
e88b30f6
...
...
@@ -4,9 +4,9 @@
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Mon Mar 9 21:06:43 2009 (+0100)
## Version: $Id$
## Last-Updated: T
ue Feb 28 14:32:09
2012 (+0100)
## Last-Updated: T
hu Mar 1 15:22:38
2012 (+0100)
## By: Julien Wintz
## Update #:
54
## Update #:
80
######################################################################
##
### Commentary:
...
...
@@ -17,18 +17,52 @@
##
######################################################################
## #################################################################
## dtkLog examples
## #################################################################
add_subdirectory
(
dtkLogger
)
## #################################################################
## dtkCrypto examples
## #################################################################
add_subdirectory
(
dtkLicenseManager
)
## #################################################################
## dtkCore examples
## #################################################################
add_subdirectory
(
dtkAbstractDataComposite
)
add_subdirectory
(
dtkReferenceCounting
)
add_subdirectory
(
dtkUpdater
)
## #################################################################
## dtkGui examples
## #################################################################
add_subdirectory
(
dtkInterpreter
)
add_subdirectory
(
dtkLog
)
add_subdirectory
(
dtkTagCloud
)
add_subdirectory
(
dtkTextEditor
)
add_subdirectory
(
dtkUpdater
)
add_subdirectory
(
dtkSettingsEditor
)
add_subdirectory
(
dtkLicenseManager
)
add_subdirectory
(
dtkReferenceCounting
)
add_subdirectory
(
dtkFinder
)
add_subdirectory
(
dtkAboutPlugin
)
add_subdirectory
(
dtkFlowLayout
)
## #################################################################
## dtkVr examples
## #################################################################
add_subdirectory
(
dtkVrGestureRecognizer
)
## #################################################################
## dtkPlot examples
## #################################################################
add_subdirectory
(
dtkPlotEcg
)
add_subdirectory
(
dtkAboutPlugin
)
add_subdirectory
(
dtkAbstractDataComposite
)
## #################################################################
## dtkComposer examples
## #################################################################
add_subdirectory
(
dtkComposerTransmitter
)
add_subdirectory
(
dtkFlowLayout
)
examples/dtkLog/main.cpp
deleted
100644 → 0
View file @
ed076e3e
/* main.cpp ---
*
* Author: Jean-Christophe Lombardo
* Copyright (C) 2009 - Jean-Christophe Lombardo, Inria
* Created: Fri May 15 13:48:29 2009
* Version: $Id$
* Last-Updated: Wed Aug 5 10:57:25 2009 (+0200)
* By: Julien Wintz
* Update #: 37
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include
<dtkCore/dtkLog.h>
#include
<dtkGui/dtkTextEditor.h>
#include
<QtCore>
#include
<QtGui>
// /////////////////////////////////////////////////////////////////
// log messages handlers
// /////////////////////////////////////////////////////////////////
void
toFile
(
dtkLog
::
Level
level
,
const
QString
&
msg
);
void
toWidget
(
dtkLog
::
Level
level
,
const
QString
&
msg
);
// /////////////////////////////////////////////////////////////////
// Dummy thread classes to test thread safety
// /////////////////////////////////////////////////////////////////
class
Thread
:
public
QThread
{
public:
Thread
(
void
)
:
m_idx
(
++
s_idx
)
{};
void
run
(
void
)
{
QString
name
(
"Thread "
);
name
+=
QString
::
number
(
m_idx
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
dtkLog
::
output
(
name
)
<<
name
<<
" writing on ("
<<
name
<<
") output log - #"
<<
i
;
dtkLog
::
output
()
<<
name
<<
" writing on default output log - #"
<<
i
;
dtkLog
::
error
(
name
)
<<
name
<<
" writing on ("
<<
name
<<
") error log - #"
<<
i
;
dtkLog
::
error
()
<<
name
<<
" writing on default error log - #"
<<
i
;
usleep
(
100
);
}
}
private:
int
m_idx
;
static
int
s_idx
;
};
int
Thread
::
s_idx
=
0
;
// /////////////////////////////////////////////////////////////////
// Log handler example - redirection to file
// /////////////////////////////////////////////////////////////////
void
toFile
(
dtkLog
::
Level
level
,
const
QString
&
msg
)
{
QTemporaryFile
file
(
"dtk.log"
);
file
.
setAutoRemove
(
false
);
// if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
// return;
QTextStream
out
(
&
file
);
out
<<
msg
<<
"
\n
"
;
file
.
close
();
}
// /////////////////////////////////////////////////////////////////
// Log handler example - redirection to aware widget
// /////////////////////////////////////////////////////////////////
dtkTextEditor
*
widget
=
0
;
void
toWidget
(
dtkLog
::
Level
level
,
const
QString
&
msg
)
{
QCoreApplication
::
postEvent
(
widget
,
new
dtkLogEvent
(
level
,
msg
));
}
// /////////////////////////////////////////////////////////////////
// dtkLog example
// /////////////////////////////////////////////////////////////////
#include
<iostream>
int
main
(
int
argc
,
char
*
argv
[])
{
QApplication
app
(
argc
,
argv
);
widget
=
new
dtkTextEditor
;
widget
->
show
();
qDebug
()
<<
"Setting up file handler - see /tmp/dtk.log on unix and mac, %TEMP%/dtk.log on windows"
;
qDebug
()
<<
"Setting up widget handler - see text editor"
;
dtkLog
::
registerHandler
(
toFile
);
dtkLog
::
registerHandler
(
toWidget
);
std
::
cerr
<<
"cerr is redirected into default dtkLog"
<<
1
<<
", "
<<
1.0
<<
std
::
endl
;
std
::
cout
<<
"cout is redirected into default dtkLog"
<<
1
<<
", "
<<
1.0
<<
std
::
endl
;
std
::
clog
<<
"clog is redirected into default dtkLog"
<<
1
<<
", "
<<
1.0
<<
std
::
endl
;
dtkLog
::
output
()
<<
"multiple type can be logged out "
<<
1
<<
", "
<<
1.0
;
dtkLog
::
error
()
<<
"multiple type can be logged out "
<<
1
<<
", "
<<
1.0
;
dtkLog
::
output
()
<<
"This is the output channel - for default source -"
;
dtkLog
::
error
()
<<
"This is the error channel - for default source -"
;
dtkLog
::
debug
()
<<
"This is the debug channel - for default source -"
;
dtkLog
::
warning
()
<<
"This is the warning channel - for default source -"
;
dtkLog
::
critical
()
<<
"This is the critical channel - for default source -"
;
dtkLog
::
fatal
()
<<
"This is the fatal channel - for default source -"
;
Thread
t
[
20
];
for
(
unsigned
int
i
=
0
;
i
<
5
;
++
i
)
t
[
i
].
start
();
for
(
unsigned
int
i
=
0
;
i
<
5
;
++
i
)
t
[
i
].
wait
();
for
(
unsigned
int
i
=
0
;
i
<
500
;
++
i
)
app
.
processEvents
();
dtkLog
::
warning
()
<<
"Disabling standard redirections"
;
dtkLog
::
disableRedirection
();
std
::
cerr
<<
"cerr is no more redirected into default dtkLog"
<<
std
::
endl
;
std
::
cout
<<
"cout is no more redirected into default dtkLog"
<<
std
::
endl
;
std
::
clog
<<
"clog is no more redirected into default dtkLog"
<<
std
::
endl
;
return
app
.
exec
();
}
// -*- tab-width: 4; indent-tabs-mode: nil c-basic-offset: 4 -*-
// vim:cindent:ts=4:sw=4:et:tw=80:sta:
examples/dtkLog/CMakeLists.txt
→
examples/dtkLog
ger
/CMakeLists.txt
View file @
e88b30f6
### CMakeLists.txt ---
##
## Author: J
ean-Christophe Lombardo
## Copyright (C) 200
9 - Jean-Christophe Lombardo
, Inria
## Created:
Fri
Ma
y
1
5
1
3:46:51 2009
## Author: J
ulien Wintz
## Copyright (C) 200
8-2011 - Julien Wintz
, Inria
.
## Created:
Thu
Ma
r
1 1
5:20:19 2012 (+0100)
## Version: $Id$
## Last-Updated: T
ue Apr 6 09:17:5
9 201
0
(+0
2
00)
## Last-Updated: T
hu Mar 1 15:23:0
9 201
2
(+0
1
00)
## By: Julien Wintz
## Update #: 5
##
######################################################################
##
### Commentary:
...
...
@@ -18,16 +17,15 @@
##
######################################################################
project
(
dtkLog
)
project
(
dtkLog
ger
)
## #################################################################
## Build rules
## #################################################################
add_executable
(
${
PROJECT_NAME
}
MACOSX_BUNDLE
add_executable
(
${
PROJECT_NAME
}
main.cpp
)
target_link_libraries
(
${
PROJECT_NAME
}
${
QT_LIBRARIES
}
dtkCore
dtkGui
)
dtkLog
)
examples/dtkLogger/main.cpp
0 → 100644
View file @
e88b30f6
/* main.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:23:18 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 23:14:39 2012 (+0100)
* By: Julien Wintz
* Update #: 225
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include
<dtkLog/dtkLog.h>
#include
<QtCore>
#include
<QtDebug>
// /////////////////////////////////////////////////////////////////
// QVariant compliant custom class
// /////////////////////////////////////////////////////////////////
class
Pixel
{
public:
Pixel
(
void
);
Pixel
(
int
x
,
int
y
);
Pixel
(
const
Pixel
&
other
);
~
Pixel
(
void
);
private:
friend
QDebug
operator
<<
(
QDebug
dbg
,
const
Pixel
&
pixel
);
private:
int
m_x
;
int
m_y
;
};
Pixel
::
Pixel
(
void
)
{
this
->
m_x
=
0
;
this
->
m_y
=
0
;
}
Pixel
::
Pixel
(
int
x
,
int
y
)
{
this
->
m_x
=
x
;
this
->
m_y
=
y
;
}
Pixel
::
Pixel
(
const
Pixel
&
other
)
{
this
->
m_x
=
other
.
m_x
;
this
->
m_y
=
other
.
m_y
;
}
Pixel
::~
Pixel
(
void
)
{
}
QDebug
operator
<<
(
QDebug
dbg
,
const
Pixel
&
pixel
)
{
dbg
.
nospace
()
<<
"Pixel("
<<
pixel
.
m_x
<<
", "
<<
pixel
.
m_y
<<
")"
;
return
dbg
.
space
();
}
Q_DECLARE_METATYPE
(
Pixel
);
// /////////////////////////////////////////////////////////////////
// Helper function
// /////////////////////////////////////////////////////////////////
QString
dtkLogPath
(
QCoreApplication
*
application
);
// /////////////////////////////////////////////////////////////////
// main
// /////////////////////////////////////////////////////////////////
int
main
(
int
argc
,
char
**
argv
)
{
QCoreApplication
application
(
argc
,
argv
);
application
.
setApplicationName
(
argv
[
0
]);
qRegisterMetaType
<
Pixel
>
();
dtkLogger
::
instance
().
setLevel
(
dtkLog
::
Trace
);
dtkLogger
::
instance
().
attachConsole
();
dtkLogger
::
instance
().
attachFile
(
dtkLogPath
(
&
application
));
// /////////////////////////////////////////////////////////////////
qDebug
()
<<
"Overview of logging levels:"
;
dtkTrace
()
<<
"More detailed information."
;
dtkDebug
()
<<
"Detailed information on the flow through the system."
;
dtkInfo
()
<<
"Interesting runtime events (startup/shutdown)."
;
dtkWarn
()
<<
"Runtime situations that are undesirable or unexpected, but not necessarily wrong."
;
dtkError
()
<<
"Other runtime errors or unexpected conditions."
;
dtkFatal
()
<<
"Severe errors that cause premature termination."
;
qDebug
()
<<
""
;
// /////////////////////////////////////////////////////////////////
dtkLogger
::
instance
().
setLevel
(
dtkLog
::
Info
);
qDebug
()
<<
"Level management (current Level is dtkLog::Info):"
;
dtkTrace
()
<<
"This message is logged as TRACE < INFO"
;
dtkDebug
()
<<
"This message is logged as DEBUG < INFO"
;
dtkInfo
()
<<
"This message is logged as INFO == INFO"
;
dtkWarn
()
<<
"This message is logged as WARN >= INFO"
;
dtkError
()
<<
"This message is logged as ERROR >= INFO"
;
dtkFatal
()
<<
"This message is logged as FATAL >= INFO"
;
qDebug
()
<<
""
;
dtkLogger
::
instance
().
setLevel
(
dtkLog
::
Trace
);
// /////////////////////////////////////////////////////////////////
dtkLogger
::
instance
().
detachFile
(
dtkLogPath
(
&
application
));
qDebug
()
<<
"Destination management:"
;
dtkTrace
()
<<
"This message will no longer be logged to the file"
;
dtkDebug
()
<<
"This message will no longer be logged to the file"
;
dtkLogger
::
instance
().
attachFile
(
dtkLogPath
(
&
application
));
dtkDebug
()
<<
"This message will be logged to the file"
;
qDebug
()
<<
""
;
// /////////////////////////////////////////////////////////////////
QList
<
int
>
list
;
list
<<
1
;
list
<<
2
<<
3
;
QHash
<
int
,
QString
>
hash
;
hash
.
insert
(
1
,
"one"
);
hash
.
insert
(
2
,
"two"
);
hash
.
insert
(
3
,
"three"
);
Pixel
p
(
100
,
250
);
QVariant
variant
;
variant
.
setValue
(
p
);
qDebug
()
<<
"Handled types:"
;
dtkTrace
()
<<
"Primitive types -"
<<
true
<<
1
<<
2.2
;
dtkDebug
()
<<
"Qt types -"
<<
QString
(
"String"
)
<<
QChar
(
'x'
)
<<
QRect
(
0
,
10
,
50
,
40
);
dtkError
()
<<
"Qt containers -"
<<
list
<<
hash
;
dtkFatal
()
<<
"Custom types -"
<<
p
<<
variant
;
qDebug
()
<<
""
;
int
status
=
0
;
dtkInfo
()
<<
"Program exited with return code"
<<
status
;
return
status
;
}
// /////////////////////////////////////////////////////////////////
// Helper function
// /////////////////////////////////////////////////////////////////
QString
dtkLogPath
(
QCoreApplication
*
application
)
{
return
QDir
(
application
->
applicationDirPath
()).
filePath
(
QString
(
"%1.log"
).
arg
(
application
->
applicationName
()));
}
src/CMakeLists.txt
View file @
e88b30f6
...
...
@@ -4,9 +4,9 @@
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Mon Jul 20 19:22:37 2009 (+0200)
## Version: $Id$
## Last-Updated:
Mon Jan 30 14:28:13
2012 (+0100)
## Last-Updated:
Thu Mar 1 14:37:24
2012 (+0100)
## By: Julien Wintz
## Update #:
39
## Update #:
40
######################################################################
##
### Commentary:
...
...
@@ -17,6 +17,7 @@
##
######################################################################
add_subdirectory
(
dtkLog
)
add_subdirectory
(
dtkMath
)
add_subdirectory
(
dtkZip
)
add_subdirectory
(
dtkCore
)
...
...
src/dtkLog/CMakeLists.txt
0 → 100644
View file @
e88b30f6
### CMakeLists.txt ---
##
## Author: Julien Wintz
## Copyright (C) 2008-2011 - Julien Wintz, Inria.
## Created: Thu Mar 1 14:34:49 2012 (+0100)
## Version: $Id$
## Last-Updated: Thu Mar 1 17:29:16 2012 (+0100)
## By: Julien Wintz
## Update #: 19
######################################################################
##
### Commentary:
##
######################################################################
##
### Change log:
##
######################################################################
project
(
dtkLog
)
## #################################################################
## Sources
## #################################################################
set
(
${
PROJECT_NAME
}
_HEADERS
dtkLog.h
dtkLogger.h
dtkLogEngine.h
dtkLogDestination.h
)
set
(
${
PROJECT_NAME
}
_HEADERS_MOC
)
set
(
${
PROJECT_NAME
}
_SOURCES
dtkLogger.cpp
dtkLogEngine.cpp
dtkLogDestination.cpp
)
## #################################################################
## Build rules
## #################################################################
if
(
NOT WIN32
)
add_definitions
(
-Wno-write-strings
)
add_definitions
(
-Wformat=0
)
endif
(
NOT WIN32
)
add_definitions
(
${
QT_DEFINITIONS
}
)
add_definitions
(
-DQT_SHARED
)
if
(
NOT WIN32
)
add_definitions
(
-DQT_NO_DEBUG
)
endif
(
NOT WIN32
)
qt4_wrap_cpp
(
${
PROJECT_NAME
}
_SOURCES_MOC
${${
PROJECT_NAME
}
_HEADERS_MOC
}
)
if
(
BUILD_SHARED_LIBS
)
add_library
(
${
PROJECT_NAME
}
SHARED
${${
PROJECT_NAME
}
_SOURCES
}
${${
PROJECT_NAME
}
_HEADERS
}
${${
PROJECT_NAME
}
_SOURCES_MOC
}
)
else
(
BUILD_SHARED_LIBS
)
add_library
(
${
PROJECT_NAME
}
STATIC
${${
PROJECT_NAME
}
_SOURCES
}
${${
PROJECT_NAME
}
_HEADERS
}
${${
PROJECT_NAME
}
_SOURCES_MOC
}
)
endif
(
BUILD_SHARED_LIBS
)
target_link_libraries
(
${
PROJECT_NAME
}
${
QT_LIBRARIES
}
)
## #################################################################
## Source file layout in development environments like Visual Studio
## #################################################################
SOURCE_GROUP
(
"Header Files"
REGULAR_EXPRESSION .*\\.h\$
)
SOURCE_GROUP
(
"Generated Files"
FILES
${${
PROJECT_NAME
}
_SOURCES_MOC
}
)
## #################################################################
## Installation
## #################################################################
foreach
(
header
${${
PROJECT_NAME
}
_HEADERS
}
)
string
(
REGEX REPLACE
"(.*)
\\
.h
\$
"
"
\\
1"
h
${
header
}
)
set
(
${
PROJECT_NAME
}
_HEADERS_QTS
"
${${
PROJECT_NAME
}
_HEADERS_QTS
}
"
${
h
}
)
endforeach
(
header
)
install
(
FILES
${${
PROJECT_NAME
}
_HEADERS
}
DESTINATION include/
${
PROJECT_NAME
}
)
install
(
FILES
${${
PROJECT_NAME
}
_HEADERS_QTS
}
DESTINATION include/
${
PROJECT_NAME
}
)
install
(
TARGETS
${
PROJECT_NAME
}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
src/dtkLog/dtkLog.cpp
0 → 100644
View file @
e88b30f6
/* dtkLog.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 14:40:12 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 17:22:40 2012 (+0100)
* By: Julien Wintz
* Update #: 31
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include
"dtkLog.h"
src/dtkLog/dtkLog.h
0 → 100644
View file @
e88b30f6
/* dtkLog.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 14:37:36 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 21:20:39 2012 (+0100)
* By: Julien Wintz
* Update #: 126
*/
/* Commentary: See credits at EOF.
*
*/
/* Change log:
*
*/
#ifndef DTKLOG_H
#define DTKLOG_H
namespace
dtkLog
{
enum
Level
{
Trace
=
0x000
,
Debug
=
0x001
,
Info
=
0x010
,
Warn
=
0x011
,
Error
=
0x100
,
Fatal
=
0x101
};
}
#include
"dtkLogger.h"
#include
"dtkLogDestination.h"
#include
"dtkLogEngine.h"
// /////////////////////////////////////////////////////////////////
// Trace level stream
// /////////////////////////////////////////////////////////////////
#define dtkTrace() \
if (dtkLogger::instance().level() > dtkLog::Trace) \
; \
else \
dtkLogEngine(dtkLog::Trace).stream()
// /////////////////////////////////////////////////////////////////
// Debug level stream
// /////////////////////////////////////////////////////////////////
#define dtkDebug() \
if (dtkLogger::instance().level() > dtkLog::Debug) \
; \
else \
dtkLogEngine(dtkLog::Debug).stream()
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
#define dtkInfo() \
if (dtkLogger::instance().level() > dtkLog::Info) \
; \