Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
e9afbc98
Commit
e9afbc98
authored
Feb 23, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'topic/logger'
parents
990e60d5
c736d978
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
56 deletions
+39
-56
libcaf_core/caf/logger.hpp
libcaf_core/caf/logger.hpp
+5
-21
libcaf_core/src/logger.cpp
libcaf_core/src/logger.cpp
+32
-33
libcaf_core/test/thread_hook.cpp
libcaf_core/test/thread_hook.cpp
+2
-2
No files found.
libcaf_core/caf/logger.hpp
View file @
e9afbc98
...
...
@@ -320,6 +320,8 @@ private:
void
init
(
actor_system_config
&
cfg
);
bool
open_file
();
// -- event handling ---------------------------------------------------------
void
handle_event
(
const
event
&
x
);
...
...
@@ -375,6 +377,9 @@ private:
// Filled with log events by other threads.
detail
::
ringbuffer
<
event
,
queue_size
>
queue_
;
// Stores the assembled name of the log file.
std
::
string
file_name_
;
// Executes `logger::run`.
std
::
thread
thread_
;
};
...
...
@@ -435,25 +440,6 @@ bool operator==(const logger::field& x, const logger::field& y);
// -- logging macros -----------------------------------------------------------
#if CAF_LOG_LEVEL == CAF_LOG_LEVEL_QUIET
#define CAF_LOG_IMPL(unused1, unused2, unused3)
// placeholder macros when compiling without logging
inline
caf
::
actor_id
caf_set_aid_dummy
()
{
return
0
;
}
#define CAF_PUSH_AID(unused) CAF_VOID_STMT
#define CAF_PUSH_AID_FROM_PTR(unused) CAF_VOID_STMT
#define CAF_SET_AID(unused) caf_set_aid_dummy()
#define CAF_SET_LOGGER_SYS(unused) CAF_VOID_STMT
#define CAF_LOG_TRACE(unused)
#else // CAF_LOG_LEVEL == CAF_LOG_LEVEL_QUIET
#define CAF_LOG_IMPL(component, loglvl, message) \
do { \
auto CAF_UNIFYN(caf_logger) = caf::logger::current_logger(); \
...
...
@@ -518,8 +504,6 @@ inline caf::actor_id caf_set_aid_dummy() { return 0; }
#define CAF_LOG_ERROR(output) \
CAF_LOG_IMPL(CAF_LOG_COMPONENT, CAF_LOG_LEVEL_ERROR, output)
#endif // CAF_LOG_LEVEL == CAF_LOG_LEVEL_QUIET
#ifndef CAF_LOG_INFO
#define CAF_LOG_INFO(output) CAF_VOID_STMT
#define CAF_LOG_INFO_IF(cond, output) CAF_VOID_STMT
...
...
libcaf_core/src/logger.cpp
View file @
e9afbc98
...
...
@@ -188,8 +188,6 @@ string_view reduce_symbol(std::ostream& out, string_view symbol) {
return
symbol
;
}
#if CAF_LOG_LEVEL >= 0
#if defined(CAF_NO_THREAD_LOCAL)
pthread_key_t
s_key
;
...
...
@@ -232,17 +230,6 @@ inline logger* get_current_logger() {
#endif // CAF_NO_THREAD_LOCAL
#else // CAF_LOG_LEVEL
inline
void
set_current_logger
(
logger
*
)
{
// nop
}
inline
logger
*
get_current_logger
()
{
return
nullptr
;
}
#endif // CAF_LOG_LEVEL
}
// namespace <anonymous>
logger
::
config
::
config
()
...
...
@@ -358,7 +345,7 @@ bool logger::accepts(unsigned level, atom_value cname) {
[
=
](
atom_value
name
)
{
return
name
==
cname
;
});
}
logger
::
logger
(
actor_system
&
sys
)
:
system_
(
sys
)
{
logger
::
logger
(
actor_system
&
sys
)
:
system_
(
sys
)
,
t0_
(
make_timestamp
())
{
// nop
}
...
...
@@ -404,6 +391,17 @@ void logger::init(actor_system_config& cfg) {
}
}
bool
logger
::
open_file
()
{
if
(
file_verbosity
()
==
CAF_LOG_LEVEL_QUIET
||
file_name_
.
empty
())
return
false
;
file_
.
open
(
file_name_
,
std
::
ios
::
out
|
std
::
ios
::
app
);
if
(
!
file_
)
{
std
::
cerr
<<
"unable to open log file "
<<
file_name_
<<
std
::
endl
;
return
false
;
}
return
true
;
}
void
logger
::
render_fun_prefix
(
std
::
ostream
&
out
,
const
event
&
x
)
{
// Extract the prefix of a function name. For example:
// virtual std::vector<int> my::namespace::foo(int);
...
...
@@ -550,6 +548,8 @@ void logger::run() {
queue_
.
wait_nonempty
();
if
(
queue_
.
front
().
message
.
empty
())
return
;
if
(
!
open_file
()
&&
console_verbosity
()
==
CAF_LOG_LEVEL_QUIET
)
return
;
log_first_line
();
// Loop until receiving an empty message.
for
(;;)
{
...
...
@@ -635,49 +635,48 @@ void logger::start() {
parent_thread_
=
std
::
this_thread
::
get_id
();
if
(
verbosity
()
==
CAF_LOG_LEVEL_QUIET
)
return
;
t0_
=
make_timestamp
();
auto
f
=
get_or
(
system_
.
config
(),
"logger.file-name"
,
file_name_
=
get_or
(
system_
.
config
(),
"logger.file-name"
,
defaults
::
logger
::
file_name
);
if
(
f
.
empty
())
{
if
(
f
ile_name_
.
empty
())
{
// No need to continue if console and log file are disabled.
if
(
console_verbosity
()
==
CAF_LOG_LEVEL_QUIET
)
return
;
}
else
{
// Replace placeholders.
const
char
pid
[]
=
"[PID]"
;
auto
i
=
std
::
search
(
f
.
begin
(),
f
.
end
(),
std
::
begin
(
pid
),
auto
i
=
std
::
search
(
f
ile_name_
.
begin
(),
file_name_
.
end
(),
std
::
begin
(
pid
),
std
::
end
(
pid
)
-
1
);
if
(
i
!=
f
.
end
())
{
if
(
i
!=
f
ile_name_
.
end
())
{
auto
id
=
std
::
to_string
(
detail
::
get_process_id
());
f
.
replace
(
i
,
i
+
sizeof
(
pid
)
-
1
,
id
);
f
ile_name_
.
replace
(
i
,
i
+
sizeof
(
pid
)
-
1
,
id
);
}
const
char
ts
[]
=
"[TIMESTAMP]"
;
i
=
std
::
search
(
f
.
begin
(),
f
.
end
(),
std
::
begin
(
ts
),
std
::
end
(
ts
)
-
1
);
if
(
i
!=
f
.
end
())
{
i
=
std
::
search
(
file_name_
.
begin
(),
file_name_
.
end
(),
std
::
begin
(
ts
),
std
::
end
(
ts
)
-
1
);
if
(
i
!=
file_name_
.
end
())
{
auto
t0_str
=
timestamp_to_string
(
t0_
);
f
.
replace
(
i
,
i
+
sizeof
(
ts
)
-
1
,
t0_str
);
f
ile_name_
.
replace
(
i
,
i
+
sizeof
(
ts
)
-
1
,
t0_str
);
}
const
char
node
[]
=
"[NODE]"
;
i
=
std
::
search
(
f
.
begin
(),
f
.
end
(),
std
::
begin
(
node
),
std
::
end
(
node
)
-
1
);
if
(
i
!=
f
.
end
())
{
i
=
std
::
search
(
file_name_
.
begin
(),
file_name_
.
end
(),
std
::
begin
(
node
),
std
::
end
(
node
)
-
1
);
if
(
i
!=
file_name_
.
end
())
{
auto
nid
=
to_string
(
system_
.
node
());
f
.
replace
(
i
,
i
+
sizeof
(
node
)
-
1
,
nid
);
}
file_
.
open
(
f
,
std
::
ios
::
out
|
std
::
ios
::
app
);
if
(
!
file_
)
{
std
::
cerr
<<
"unable to open log file "
<<
f
<<
std
::
endl
;
return
;
file_name_
.
replace
(
i
,
i
+
sizeof
(
node
)
-
1
,
nid
);
}
}
if
(
cfg_
.
inline_output
)
if
(
cfg_
.
inline_output
)
{
// Open file immediately for inline output.
open_file
();
log_first_line
();
else
}
else
{
thread_
=
std
::
thread
{[
this
]
{
detail
::
set_thread_name
(
"caf.logger"
);
this
->
system_
.
thread_started
();
this
->
run
();
this
->
system_
.
thread_terminates
();
}};
}
}
void
logger
::
stop
()
{
...
...
libcaf_core/test/thread_hook.cpp
View file @
e9afbc98
...
...
@@ -121,7 +121,7 @@ CAF_TEST(counting_system_without_actor) {
assumed_init_calls
=
1
;
assumed_thread_count
=
get_or
(
cfg
,
"scheduler.max-threads"
,
defaults
::
scheduler
::
max_threads
)
+
1
;
// caf.clock thread
+
2
;
// caf.clock and caf.logger
auto
&
sched
=
sys
.
scheduler
();
if
(
sched
.
detaches_utility_actors
())
assumed_thread_count
+=
sched
.
num_utility_actors
();
...
...
@@ -131,7 +131,7 @@ CAF_TEST(counting_system_with_actor) {
assumed_init_calls
=
1
;
assumed_thread_count
=
get_or
(
cfg
,
"scheduler.max-threads"
,
defaults
::
scheduler
::
max_threads
)
+
2
;
// caf.clock thread plus
detached actor
+
3
;
// caf.clock, caf.logger, and
detached actor
auto
&
sched
=
sys
.
scheduler
();
if
(
sched
.
detaches_utility_actors
())
assumed_thread_count
+=
sched
.
num_utility_actors
();
...
...
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