Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
eec26e48
Commit
eec26e48
authored
Sep 29, 2009
by
schurade
Browse files
[CHANGE] further work on the logger
parent
91f64e84
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
38 deletions
+62
-38
src/common/WLogEntry.h
src/common/WLogEntry.h
+20
-4
src/common/WLogger.cpp
src/common/WLogger.cpp
+26
-26
src/common/WLogger.h
src/common/WLogger.h
+16
-8
No files found.
src/common/WLogEntry.h
View file @
eec26e48
...
...
@@ -42,14 +42,34 @@ LogLevel;
class
WLogEntry
{
public:
/**
*
*/
WLogEntry
(
std
::
string
logTime
,
std
::
string
message
,
LogLevel
level
,
std
::
string
source
);
/**
*
*/
virtual
~
WLogEntry
();
/**
*
*/
std
::
string
getLogString
(
std
::
string
format
=
"[%t] *%l* %m
\n
"
);
/**
*
*/
LogLevel
getLogLevel
();
protected:
private:
/**
* Private standard constructor to prevent empty log entries
*/
WLogEntry
();
/**
*
*/
...
...
@@ -69,10 +89,6 @@ protected:
*
*/
std
::
string
m_source
;
private:
WLogEntry
();
};
#endif // WLOGENTRY_H
src/common/WLogger.cpp
View file @
eec26e48
...
...
@@ -30,12 +30,6 @@
#include "WLogger.h"
WLogger
::
WLogger
()
:
WThreadedRunner
()
{
init
();
}
WLogger
::
WLogger
(
std
::
string
fileName
,
LogLevel
level
)
:
WThreadedRunner
(),
...
...
@@ -44,8 +38,13 @@ WLogger::WLogger( std::string fileName, LogLevel level ):
m_STDOUTLevel
(
level
),
m_STDERRLevel
(
LL_ERROR
),
m_LogFileLevel
(
level
),
m_LogFileName
(
fileName
)
m_LogFileName
(
fileName
),
m_FinishRequested
(
false
)
{
addLogMessage
(
"Initalizing Logger"
,
"Logger"
,
LL_DEBUG
);
addLogMessage
(
"==============================================================================="
,
"Logger"
,
LL_INFO
);
addLogMessage
(
"= Starting Log Session ="
,
"Logger"
,
LL_INFO
);
addLogMessage
(
"==============================================================================="
,
"Logger"
,
LL_INFO
);
}
WLogger
::~
WLogger
()
...
...
@@ -86,23 +85,6 @@ void WLogger::setLogFileName( std::string fileName )
}
bool
WLogger
::
init
()
{
m_LogLevel
=
LL_DEBUG
;
m_STDOUTLevel
=
LL_DEBUG
;
m_STDERRLevel
=
LL_ERROR
;
m_LogFileLevel
=
LL_DEBUG
;
m_LogFileName
=
"walnut.log"
;
addLogMessage
(
"Initalizing Logger"
,
"Logger"
,
LL_DEBUG
);
addLogMessage
(
"==============================================================================="
,
"Logger"
,
LL_INFO
);
addLogMessage
(
"= Starting Log Session ="
,
"Logger"
,
LL_INFO
);
addLogMessage
(
"==============================================================================="
,
"Logger"
,
LL_INFO
);
return
true
;
}
void
WLogger
::
addLogMessage
(
std
::
string
message
,
std
::
string
source
,
LogLevel
level
)
{
if
(
m_LogLevel
>
level
)
...
...
@@ -113,15 +95,19 @@ void WLogger::addLogMessage( std::string message, std::string source, LogLevel l
boost
::
posix_time
::
ptime
t
(
boost
::
posix_time
::
second_clock
::
local_time
()
);
std
::
string
timeString
(
to_simple_string
(
t
)
);
WLogEntry
entry
(
timeString
,
message
,
level
,
source
);
boost
::
mutex
::
scoped_lock
l
(
m_QueueMutex
);
m_LogQueue
.
push
(
entry
);
// TODO(schurade): this must be called from the kernel
and made thread safe
processQueue
();
// TODO(schurade): this must be called from the kernel
//
processQueue();
}
void
WLogger
::
processQueue
()
{
boost
::
mutex
::
scoped_lock
l
(
m_QueueMutex
);
while
(
!
m_LogQueue
.
empty
()
)
{
WLogEntry
entry
=
m_LogQueue
.
front
();
...
...
@@ -147,3 +133,17 @@ void WLogger::processQueue()
}
}
}
void
WLogger
::
threadMain
()
{
// Since the modules run in a separate thread: such loops are possible
while
(
!
m_FinishRequested
)
{
processQueue
();
// do fancy stuff
sleep
(
1
);
}
// clean up stuff
}
src/common/WLogger.h
View file @
eec26e48
...
...
@@ -32,6 +32,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include "../common/WThreadedRunner.h"
#include "WLogEntry.h"
...
...
@@ -42,15 +43,10 @@
class
WLogger
:
public
WThreadedRunner
{
public:
/**
* Default constructor.
*/
WLogger
();
/**
* Constructor
*/
WLogger
(
std
::
string
fileName
,
LogLevel
level
=
LL_DEBUG
);
WLogger
(
std
::
string
fileName
=
"walnut.log"
,
LogLevel
level
=
LL_DEBUG
);
/**
* Destructor.
...
...
@@ -93,7 +89,15 @@ public:
*/
void
processQueue
();
/**
* \par Description
* Entry point after loading the module. Runs in separate thread.
*/
virtual
void
threadMain
();
protected:
private:
/**
*
*/
...
...
@@ -130,11 +134,15 @@ protected:
*/
std
::
queue
<
WLogEntry
>
m_LogQueue
;
private:
/**
*
*/
bool
init
();
boost
::
mutex
m_QueueMutex
;
/**
*
*/
bool
m_FinishRequested
;
};
#endif // WLOGGER_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment