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
6289edf3
Commit
6289edf3
authored
Oct 16, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'tobim-topic/per-sink-log-level'
parents
c1724d25
02e0c920
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
47 deletions
+82
-47
examples/caf-application.ini
examples/caf-application.ini
+6
-2
libcaf_core/caf/defaults.hpp
libcaf_core/caf/defaults.hpp
+3
-2
libcaf_core/caf/logger.hpp
libcaf_core/caf/logger.hpp
+5
-2
libcaf_core/src/actor_system_config.cpp
libcaf_core/src/actor_system_config.cpp
+6
-2
libcaf_core/src/defaults.cpp
libcaf_core/src/defaults.cpp
+4
-3
libcaf_core/src/logger.cpp
libcaf_core/src/logger.cpp
+58
-36
No files found.
examples/caf-application.ini
View file @
6289edf3
...
...
@@ -63,11 +63,15 @@ enable-udp=false
file-name
=
"actor_log_[PID]_[TIMESTAMP]_[NODE].log"
; format for rendering individual log file entries
file-format
=
"%r %c %p %a %t %C %M %F:%L %m%n"
; configures the minimum severity of messages that are written to the log file
; (quiet|error|warning|info|debug|trace)
file-verbosity
=
'trace'
; mode for console log output generation (none|colored|uncolored)
console
=
'none'
; format for printing individual log entries to the console
console-format
=
"%m"
; configures the minimum severity of messages that are written to the console
; (quiet|error|warning|info|debug|trace)
console-verbosity
=
'trace'
; excludes listed components from logging
component-filter
=
""
; configures the severity level for logs (quiet|error|warning|info|debug|trace)
verbosity
=
'trace'
libcaf_core/caf/defaults.hpp
View file @
6289edf3
...
...
@@ -61,12 +61,13 @@ extern const timespan relaxed_sleep_duration;
namespace
logger
{
extern
const
atom_value
console
;
extern
const
atom_value
verbosity
;
extern
const
char
*
component_filter
;
extern
const
atom_value
console
;
extern
const
char
*
console_format
;
extern
const
atom_value
console_verbosity
;
extern
const
char
*
file_format
;
extern
const
char
*
file_name
;
extern
const
atom_value
file_verbosity
;
}
// namespace logger
...
...
libcaf_core/caf/logger.hpp
View file @
6289edf3
...
...
@@ -284,6 +284,8 @@ public:
private:
void
handle_event
(
event
&
x
);
void
handle_file_event
(
event
&
x
);
void
handle_console_event
(
event
&
x
);
void
log_first_line
();
...
...
@@ -308,7 +310,9 @@ private:
}
actor_system
&
system_
;
int
level_
;
int
max_level_
;
int
console_level_
;
int
file_level_
;
int
flags_
;
detail
::
shared_spinlock
aids_lock_
;
std
::
unordered_map
<
std
::
thread
::
id
,
actor_id
>
aids_
;
...
...
@@ -553,4 +557,3 @@ inline caf::actor_id caf_set_aid_dummy() { return 0; }
"TERMINATE ; ID =" << thisptr->id() \
<< "; REASON =" << deep_to_string(rsn).c_str() \
<< "; NODE =" << thisptr->node())
libcaf_core/src/actor_system_config.cpp
View file @
6289edf3
...
...
@@ -85,7 +85,6 @@ actor_system_config::actor_system_config()
logger_file_format
=
"%r %c %p %a %t %C %M %F:%L %m%n"
;
logger_console
=
atom
(
"none"
);
logger_console_format
=
"%m"
;
logger_verbosity
=
atom
(
"trace"
);
logger_inline_output
=
false
;
namespace
mm
=
defaults
::
middleman
;
middleman_network_backend
=
mm
::
network_backend
;
...
...
@@ -143,14 +142,19 @@ actor_system_config::actor_system_config()
"sets the filesystem path of the log file"
)
.
add
(
logger_file_format
,
"file-format"
,
"sets the line format for individual log file entires"
)
.
add
<
atom_value
>
(
"file-verbosity"
,
"sets the file output verbosity (quiet|error|warning|info|debug|trace)"
)
.
add
(
logger_console
,
"console"
,
"sets the type of output to std::clog (none|colored|uncolored)"
)
.
add
(
logger_console_format
,
"console-format"
,
"sets the line format for printing individual log entires"
)
.
add
<
atom_value
>
(
"console-verbosity"
,
"sets the console output verbosity "
"(quiet|error|warning|info|debug|trace)"
)
.
add
(
logger_component_filter
,
"component-filter"
,
"exclude all listed components from logging"
)
.
add
(
logger_verbosity
,
"verbosity"
,
"set
s the verbosity (quiet|error|warning|info|debug|trace
)"
)
"set
file and console verbosity (deprecated
)"
)
.
add
(
logger_inline_output
,
"inline-output"
,
"sets whether a separate thread is used for I/O"
);
opt_group
{
custom_options_
,
"middleman"
}
...
...
libcaf_core/src/defaults.cpp
View file @
6289edf3
...
...
@@ -48,7 +48,7 @@ const timespan desired_batch_complexity = us(50);
const
timespan
max_batch_delay
=
ms
(
5
);
const
timespan
credit_round_interval
=
ms
(
10
);
}
// namespace stream
ing
}
// namespace stream
namespace
scheduler
{
...
...
@@ -74,12 +74,13 @@ const timespan relaxed_sleep_duration = ms(10);
namespace
logger
{
const
atom_value
console
=
atom
(
"none"
);
const
atom_value
verbosity
=
atom
(
"trace"
);
const
char
*
component_filter
=
""
;
const
atom_value
console
=
atom
(
"none"
);
const
char
*
console_format
=
"%m"
;
const
atom_value
console_verbosity
=
atom
(
"trace"
);
const
char
*
file_format
=
"%r %c %p %a %t %C %M %F:%L %m%n"
;
const
char
*
file_name
=
"actor_log_[PID]_[TIMESTAMP]_[NODE].log"
;
const
atom_value
file_verbosity
=
atom
(
"trace"
);
}
// namespace logger
...
...
libcaf_core/src/logger.cpp
View file @
6289edf3
...
...
@@ -25,6 +25,7 @@
#include <fstream>
#include <algorithm>
#include <condition_variable>
#include <unordered_map>
#include "caf/config.hpp"
...
...
@@ -214,7 +215,7 @@ bool logger::accepts(int level, const char* cname_begin,
const
char
*
cname_end
)
{
CAF_ASSERT
(
cname_begin
!=
nullptr
&&
cname_end
!=
nullptr
);
CAF_ASSERT
(
level
>=
0
&&
level
<=
4
);
if
(
level
>
level_
)
if
(
level
>
max_
level_
)
return
false
;
if
(
!
component_filter
.
empty
())
{
auto
it
=
std
::
search
(
component_filter
.
begin
(),
component_filter
.
end
(),
...
...
@@ -234,52 +235,60 @@ logger::~logger() {
logger
::
logger
(
actor_system
&
sys
)
:
system_
(
sys
),
level_
(
CAF_LOG_LEVEL
),
max_
level_
(
CAF_LOG_LEVEL
),
flags_
(
0
),
queue_
(
policy
{})
{
// nop
}
void
logger
::
init
(
actor_system_config
&
cfg
)
{
CAF_IGNORE_UNUSED
(
cfg
);
#if CAF_LOG_LEVEL >= 0
namespace
lg
=
defaults
::
logger
;
component_filter
=
get_or
(
cfg
,
"logger.component-filter"
,
lg
::
component_filter
);
// Parse the configured log level.
auto
verbosity
=
get_or
(
cfg
,
"logger.verbosity"
,
lg
::
verbosity
);
switch
(
static_cast
<
uint64_t
>
(
verbosity
))
{
namespace
{
int
to_level_int
(
const
atom_value
atom
)
{
switch
(
atom_uint
(
atom
))
{
case
atom_uint
(
"quiet"
):
case
atom_uint
(
"QUIET"
):
level_
=
CAF_LOG_LEVEL_QUIET
;
break
;
return
CAF_LOG_LEVEL_QUIET
;
case
atom_uint
(
"error"
):
case
atom_uint
(
"ERROR"
):
level_
=
CAF_LOG_LEVEL_ERROR
;
break
;
return
CAF_LOG_LEVEL_ERROR
;
case
atom_uint
(
"warning"
):
case
atom_uint
(
"WARNING"
):
level_
=
CAF_LOG_LEVEL_WARNING
;
break
;
return
CAF_LOG_LEVEL_WARNING
;
case
atom_uint
(
"info"
):
case
atom_uint
(
"INFO"
):
level_
=
CAF_LOG_LEVEL_INFO
;
break
;
return
CAF_LOG_LEVEL_INFO
;
case
atom_uint
(
"debug"
):
case
atom_uint
(
"DEBUG"
):
level_
=
CAF_LOG_LEVEL_DEBUG
;
break
;
return
CAF_LOG_LEVEL_DEBUG
;
case
atom_uint
(
"trace"
):
case
atom_uint
(
"TRACE"
):
level_
=
CAF_LOG_LEVEL_TRACE
;
break
;
return
CAF_LOG_LEVEL_TRACE
;
default:
{
// nop
}
}
return
CAF_LOG_LEVEL_QUIET
;
}
}
// namespace
void
logger
::
init
(
actor_system_config
&
cfg
)
{
CAF_IGNORE_UNUSED
(
cfg
);
#if CAF_LOG_LEVEL >= 0
namespace
lg
=
defaults
::
logger
;
component_filter
=
get_or
(
cfg
,
"logger.component-filter"
,
lg
::
component_filter
);
// Parse the configured log level.
auto
verbosity
=
get_if
<
atom_value
>
(
&
cfg
,
"logger.verbosity"
);
auto
file_verbosity
=
verbosity
?
*
verbosity
:
lg
::
file_verbosity
;
auto
console_verbosity
=
verbosity
?
*
verbosity
:
lg
::
console_verbosity
;
file_verbosity
=
get_or
(
cfg
,
"logger.file-verbosity"
,
file_verbosity
);
console_verbosity
=
get_or
(
cfg
,
"logger.console-verbosity"
,
console_verbosity
);
file_level_
=
to_level_int
(
file_verbosity
);
console_level_
=
to_level_int
(
console_verbosity
);
max_level_
=
std
::
max
(
file_level_
,
console_level_
);
// Parse the format string.
file_format_
=
parse_format
(
get_or
(
cfg
,
"logger.file-format"
,
lg
::
file_format
));
file_format_
=
parse_format
(
get_or
(
cfg
,
"logger.file-format"
,
lg
::
file_format
));
console_format_
=
parse_format
(
get_or
(
cfg
,
"logger.console-format"
,
lg
::
console_format
));
// Set flags.
...
...
@@ -447,12 +456,15 @@ void logger::run() {
#endif
}
void
logger
::
handle_event
(
event
&
x
)
{
void
logger
::
handle_
file_
event
(
event
&
x
)
{
// Print to file if available.
if
(
file_
)
if
(
file_
&&
x
.
level
<=
file_level_
)
render
(
file_
,
file_format_
,
x
);
}
void
logger
::
handle_console_event
(
event
&
x
)
{
// Stop if no console output is configured.
if
(
!
has
(
console_output_flag
))
if
(
!
has
(
console_output_flag
)
||
x
.
level
>
console_level_
)
return
;
if
(
has
(
uncolored_console_flag
))
{
render
(
std
::
clog
,
console_format_
,
x
);
...
...
@@ -482,13 +494,19 @@ void logger::handle_event(event& x) {
}
}
void
logger
::
handle_event
(
event
&
x
)
{
handle_file_event
(
x
);
handle_console_event
(
x
);
}
void
logger
::
log_first_line
()
{
std
::
string
msg
=
"level = "
;
msg
+=
to_string
(
get_or
(
system_
.
config
(),
"logger.verbosity"
,
defaults
::
logger
::
verbosity
));
msg
+=
", node = "
;
msg
+=
to_string
(
system_
.
node
());
event
tmp
{
CAF_LOG_LEVEL_INFO
,
auto
make_event
=
[
&
](
string_view
config_val
,
const
atom_value
default_val
)
->
event
{
std
::
string
msg
=
"level = "
;
msg
+=
to_string
(
get_or
(
system_
.
config
(),
config_val
,
default_val
));
msg
+=
", node = "
;
msg
+=
to_string
(
system_
.
node
());
return
{
CAF_LOG_LEVEL_INFO
,
CAF_LOG_COMPONENT
,
CAF_PRETTY_FUN
,
__FILE__
,
...
...
@@ -497,7 +515,11 @@ void logger::log_first_line() {
std
::
this_thread
::
get_id
(),
0
,
make_timestamp
()};
handle_event
(
tmp
);
};
event
file
=
make_event
(
"logger.file-verbosity"
,
defaults
::
logger
::
file_verbosity
);
handle_file_event
(
file
);
event
console
=
make_event
(
"logger.console-verbosity"
,
defaults
::
logger
::
console_verbosity
);
handle_console_event
(
console
);
}
void
logger
::
log_last_line
()
{
...
...
@@ -516,7 +538,7 @@ void logger::log_last_line() {
void
logger
::
start
()
{
#if CAF_LOG_LEVEL >= 0
parent_thread_
=
std
::
this_thread
::
get_id
();
if
(
level_
==
CAF_LOG_LEVEL_QUIET
)
if
(
max_
level_
==
CAF_LOG_LEVEL_QUIET
)
return
;
t0_
=
make_timestamp
();
auto
f
=
get_or
(
system_
.
config
(),
"logger.file-name"
,
...
...
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