Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ApplicationCore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ChimeraTK Mirror
ApplicationCore
Commits
acca39e2
Unverified
Commit
acca39e2
authored
5 years ago
by
Martin Christoph Hierholzer
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #117 from ChimeraTK/fix_logging_issues
Fix #114 and #115
parents
e65a9752
b008ed84
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Modules/include/Logging.h
+11
-6
11 additions, 6 deletions
Modules/include/Logging.h
Modules/src/Logging.cc
+32
-21
32 additions, 21 deletions
Modules/src/Logging.cc
with
43 additions
and
27 deletions
Modules/include/Logging.h
+
11
−
6
View file @
acca39e2
...
...
@@ -189,12 +189,17 @@ namespace logging {
private:
ctk
::
VariableNetworkNode
getAccessorPair
(
const
std
::
string
&
sender
);
/** Map key is the feeding module */
std
::
map
<
std
::
string
,
ctk
::
ScalarPushInput
<
std
::
string
>
>
msg_list
;
/** Find the Message that was updated.
*/
std
::
map
<
std
::
string
,
ctk
::
ScalarPushInput
<
std
::
string
>
>::
iterator
FindSender
(
const
ChimeraTK
::
TransferElementID
&
id
);
struct
MessageSource
{
ctk
::
ScalarPushInput
<
std
::
string
>
msg
;
std
::
string
sendingModule
;
MessageSource
(
const
std
::
string
&
moduleName
,
Module
*
module
)
:
msg
{
module
,
moduleName
+
"Msg"
,
""
,
""
},
sendingModule
(
moduleName
){};
};
/** List of senders. */
std
::
vector
<
MessageSource
>
sources
;
/** Map key is the transfer id of the ScalarPushInput variable pointed to */
std
::
map
<
ChimeraTK
::
TransferElementID
,
MessageSource
*
>
id_list
;
/** Number of messages stored in the tail */
size_t
messageCounter
;
...
...
This diff is collapsed.
Click to expand it.
Modules/src/Logging.cc
+
32
−
21
View file @
acca39e2
...
...
@@ -100,25 +100,44 @@ void LoggingModule::mainLoop() {
file
.
reset
(
new
std
::
ofstream
());
messageCounter
=
0
;
std
::
stringstream
greeter
;
greeter
<<
getName
()
<<
" "
<<
getTime
()
<<
"There are "
<<
msg_list
.
size
()
greeter
<<
getName
()
<<
" "
<<
getTime
()
<<
"There are "
<<
sources
.
size
()
<<
" modules registered for logging:"
<<
std
::
endl
;
broadcastMessage
(
greeter
.
str
());
for
(
auto
&
module
:
msg_list
)
{
broadcastMessage
(
std
::
string
(
"
\t
- "
)
+
module
.
first
);
for
(
auto
module
=
sources
.
begin
();
module
!=
sources
.
end
();
module
++
)
{
broadcastMessage
(
std
::
string
(
"
\t
- "
)
+
module
->
sendingModule
);
id_list
[
module
->
msg
.
getId
()]
=
&
(
*
module
);
}
auto
group
=
readAnyGroup
();
while
(
1
)
{
auto
id
=
group
.
readAny
();
auto
sender
=
FindSender
(
id
);
if
(
id_list
.
count
(
id
)
==
0
){
throw
ChimeraTK
::
logic_error
(
"Cannot find element id"
"when updating logging variables."
);
}
std
::
string
msg
;
MessageSource
*
currentSender
;
LogLevel
level
;
try
{
currentSender
=
id_list
.
at
(
id
);
msg
=
(
std
::
string
)(
currentSender
->
msg
);
}
catch
(
std
::
out_of_range
&
e
){
throw
ChimeraTK
::
logic_error
(
"Cannot find element id"
"when updating logging variables."
);
}
try
{
level
=
static_cast
<
LogLevel
>
(
std
::
strtoul
(
&
msg
.
at
(
0
),
NULL
,
0
));
}
catch
(
std
::
out_of_range
&
e
){
throw
ChimeraTK
::
logic_error
(
"Cannot find message level"
"when updating logging variables."
);
}
if
(
targetStream
==
3
)
continue
;
auto
strlevel
=
((
std
::
string
)(
sender
->
second
))[
0
];
LogLevel
level
=
static_cast
<
LogLevel
>
(
std
::
strtoul
(
&
strlevel
,
NULL
,
0
));
LogLevel
setLevel
=
static_cast
<
LogLevel
>
((
uint
)
logLevel
);
std
::
string
tmpStr
=
(
std
::
string
)(
sender
->
second
)
;
std
::
string
tmpStr
=
msg
;
// remove message level
tmpStr
=
tmpStr
.
substr
(
1
,
tmpStr
.
size
());
std
::
stringstream
ss
;
ss
<<
level
<<
getName
()
<<
"/"
<<
sender
->
first
<<
" "
<<
getTime
()
<<
tmpStr
;
ss
<<
level
<<
getName
()
<<
"/"
<<
currentSender
->
sendingModule
<<
" "
<<
getTime
()
<<
tmpStr
;
if
(
targetStream
==
0
||
targetStream
==
1
)
{
if
(
!
((
std
::
string
)
logFile
).
empty
()
&&
!
file
->
is_open
())
{
std
::
stringstream
ss_file
;
...
...
@@ -151,24 +170,16 @@ void LoggingModule::addSource(boost::shared_ptr<Logger> logger) {
ctk
::
VariableNetworkNode
LoggingModule
::
getAccessorPair
(
const
std
::
string
&
sender
)
{
if
(
msg_list
.
count
(
sender
)
==
0
)
{
msg_list
.
emplace
(
std
::
piecewise_construct
,
std
::
make_tuple
(
sender
),
std
::
make_tuple
(
ctk
::
ScalarPushInput
<
std
::
string
>
{
this
,
sender
+
"Msg"
,
""
,
""
}));
auto
it
=
std
::
find_if
(
sources
.
begin
(),
sources
.
end
(),
boost
::
bind
(
&
MessageSource
::
sendingModule
,
_1
)
==
sender
);
if
(
it
==
sources
.
end
())
{
sources
.
emplace_back
(
MessageSource
{
sender
,
this
});
}
else
{
throw
ChimeraTK
::
logic_error
(
"Cannot add logging for module "
+
sender
+
" since logging was already added for this module."
);
}
return
msg_list
[
sender
];
}
std
::
map
<
std
::
string
,
ctk
::
ScalarPushInput
<
std
::
string
>
>::
iterator
LoggingModule
::
FindSender
(
const
ChimeraTK
::
TransferElementID
&
id
)
{
for
(
auto
it
=
msg_list
.
begin
(),
iend
=
msg_list
.
end
();
it
!=
iend
;
it
++
)
{
if
(
it
->
second
.
getId
()
==
id
)
return
it
;
}
throw
ChimeraTK
::
logic_error
(
"Cannot find element id"
"when updating logging variables."
);
return
sources
.
back
().
msg
;
}
void
LoggingModule
::
terminate
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment