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
b968f227
Commit
b968f227
authored
Jun 22, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'topic/log-component' into develop
parents
3c0b73b4
9e0bec39
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
20 deletions
+49
-20
libcaf_core/caf/logger.hpp
libcaf_core/caf/logger.hpp
+28
-9
libcaf_core/src/logger.cpp
libcaf_core/src/logger.cpp
+21
-11
No files found.
libcaf_core/caf/logger.hpp
View file @
b968f227
...
@@ -87,6 +87,17 @@ public:
...
@@ -87,6 +87,17 @@ public:
public:
public:
line_builder
();
line_builder
();
template
<
class
T
>
line_builder
&
operator
<<
(
const
T
&
x
)
{
if
(
!
str_
.
empty
())
str_
+=
" "
;
std
::
stringstream
ss
;
ss
<<
x
;
str_
+=
ss
.
str
();
behind_arg_
=
false
;
return
*
this
;
}
template
<
class
T
>
template
<
class
T
>
line_builder
&
operator
<<
(
const
arg_wrapper
<
T
>&
x
)
{
line_builder
&
operator
<<
(
const
arg_wrapper
<
T
>&
x
)
{
if
(
behind_arg_
)
if
(
behind_arg_
)
...
@@ -100,6 +111,8 @@ public:
...
@@ -100,6 +111,8 @@ public:
return
*
this
;
return
*
this
;
}
}
line_builder
&
operator
<<
(
const
std
::
string
&
str
);
line_builder
&
operator
<<
(
const
char
*
str
);
line_builder
&
operator
<<
(
const
char
*
str
);
std
::
string
get
()
const
;
std
::
string
get
()
const
;
...
@@ -123,7 +136,7 @@ public:
...
@@ -123,7 +136,7 @@ public:
actor_id
thread_local_aid
(
actor_id
aid
);
actor_id
thread_local_aid
(
actor_id
aid
);
/// Writes an entry to the log file.
/// Writes an entry to the log file.
void
log
(
int
level
,
const
std
::
string
&
class_name
,
void
log
(
int
level
,
const
char
*
component
,
const
std
::
string
&
class_name
,
const
char
*
function_name
,
const
char
*
file_name
,
const
char
*
function_name
,
const
char
*
file_name
,
int
line_num
,
const
std
::
string
&
msg
);
int
line_num
,
const
std
::
string
&
msg
);
...
@@ -135,9 +148,11 @@ public:
...
@@ -135,9 +148,11 @@ public:
static
logger
*
current_logger
();
static
logger
*
current_logger
();
static
void
log_static
(
int
level
,
const
std
::
string
&
class_name
,
static
void
log_static
(
int
level
,
const
char
*
component
,
const
char
*
function_name
,
const
char
*
file_name
,
const
std
::
string
&
class_name
,
int
line_num
,
const
std
::
string
&
msg
);
const
char
*
function_name
,
const
char
*
file_name
,
int
line_num
,
const
std
::
string
&
msg
);
/** @endcond */
/** @endcond */
...
@@ -214,9 +229,13 @@ inline caf::actor_id caf_set_aid_dummy() { return 0; }
...
@@ -214,9 +229,13 @@ inline caf::actor_id caf_set_aid_dummy() { return 0; }
#else // CAF_LOG_LEVEL
#else // CAF_LOG_LEVEL
#ifndef CAF_LOG_COMPONENT
#define CAF_LOG_COMPONENT "caf"
#endif
#define CAF_LOG_IMPL(loglvl, message) \
#define CAF_LOG_IMPL(loglvl, message) \
caf::logger::log_static(loglvl, CAF_
GET_CLASS_NAME, __func__,
\
caf::logger::log_static(loglvl, CAF_
LOG_COMPONENT, CAF_GET_CLASS_NAME,
\
__
FILE__, __LINE__,
\
__
func__, __FILE__, __LINE__,
\
(caf::logger::line_builder{} << message).get())
(caf::logger::line_builder{} << message).get())
#define CAF_PUSH_AID(aarg) \
#define CAF_PUSH_AID(aarg) \
...
@@ -254,9 +273,9 @@ inline caf::actor_id caf_set_aid_dummy() { return 0; }
...
@@ -254,9 +273,9 @@ inline caf::actor_id caf_set_aid_dummy() { return 0; }
const char* CAF_UNIFYN(func_name_) = __func__; \
const char* CAF_UNIFYN(func_name_) = __func__; \
CAF_LOG_IMPL(CAF_LOG_LEVEL_TRACE, "ENTRY" << entry_message); \
CAF_LOG_IMPL(CAF_LOG_LEVEL_TRACE, "ENTRY" << entry_message); \
auto CAF_UNIFYN(caf_log_trace_guard_) = ::caf::detail::make_scope_guard([=] {\
auto CAF_UNIFYN(caf_log_trace_guard_) = ::caf::detail::make_scope_guard([=] {\
caf::logger::log_static(CAF_LOG_LEVEL_TRACE, CAF_
GET_CLASS_NAME,
\
caf::logger::log_static(CAF_LOG_LEVEL_TRACE, CAF_
LOG_COMPONENT,
\
CAF_
UNIFYN(func_name_), __FILE__, __LINE__
, \
CAF_
GET_CLASS_NAME, CAF_UNIFYN(func_name_)
, \
"EXIT");
\
__FILE__, __LINE__, "EXIT");
\
})
})
#endif // CAF_LOG_LEVEL < CAF_LOG_LEVEL_TRACE
#endif // CAF_LOG_LEVEL < CAF_LOG_LEVEL_TRACE
...
...
libcaf_core/src/logger.cpp
View file @
b968f227
...
@@ -136,6 +136,14 @@ logger::line_builder::line_builder() : behind_arg_(false) {
...
@@ -136,6 +136,14 @@ logger::line_builder::line_builder() : behind_arg_(false) {
// nop
// nop
}
}
logger
::
line_builder
&
logger
::
line_builder
::
operator
<<
(
const
std
::
string
&
str
)
{
if
(
!
str_
.
empty
())
str_
+=
" "
;
str_
+=
str
;
behind_arg_
=
false
;
return
*
this
;
}
logger
::
line_builder
&
logger
::
line_builder
::
operator
<<
(
const
char
*
str
)
{
logger
::
line_builder
&
logger
::
line_builder
::
operator
<<
(
const
char
*
str
)
{
if
(
!
str_
.
empty
())
if
(
!
str_
.
empty
())
str_
+=
" "
;
str_
+=
" "
;
...
@@ -211,9 +219,10 @@ actor_id logger::thread_local_aid(actor_id aid) {
...
@@ -211,9 +219,10 @@ actor_id logger::thread_local_aid(actor_id aid) {
return
0
;
// was empty before
return
0
;
// was empty before
}
}
void
logger
::
log
(
int
level
,
const
std
::
string
&
class_name
,
void
logger
::
log
(
int
level
,
const
char
*
component
,
const
char
*
function_name
,
const
char
*
c_full_file_name
,
const
std
::
string
&
class_name
,
const
char
*
function_name
,
int
line_num
,
const
std
::
string
&
msg
)
{
const
char
*
c_full_file_name
,
int
line_num
,
const
std
::
string
&
msg
)
{
CAF_ASSERT
(
level
>=
0
&&
level
<=
4
);
CAF_ASSERT
(
level
>=
0
&&
level
<=
4
);
std
::
string
file_name
;
std
::
string
file_name
;
std
::
string
full_file_name
=
c_full_file_name
;
std
::
string
full_file_name
=
c_full_file_name
;
...
@@ -230,7 +239,7 @@ void logger::log(int level, const std::string& class_name,
...
@@ -230,7 +239,7 @@ void logger::log(int level, const std::string& class_name,
auto
t0
=
std
::
chrono
::
high_resolution_clock
::
now
().
time_since_epoch
();
auto
t0
=
std
::
chrono
::
high_resolution_clock
::
now
().
time_since_epoch
();
auto
ms
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
t0
).
count
();
auto
ms
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
t0
).
count
();
std
::
ostringstream
line
;
std
::
ostringstream
line
;
line
<<
ms
<<
" "
<<
log_level_name
[
level
]
<<
" "
line
<<
ms
<<
" "
<<
component
<<
" "
<<
log_level_name
[
level
]
<<
" "
<<
"actor"
<<
thread_local_aid
()
<<
" "
<<
std
::
this_thread
::
get_id
()
<<
"actor"
<<
thread_local_aid
()
<<
" "
<<
std
::
this_thread
::
get_id
()
<<
" "
<<
class_name
<<
" "
<<
function_name
<<
" "
<<
file_name
<<
":"
<<
" "
<<
class_name
<<
" "
<<
function_name
<<
" "
<<
file_name
<<
":"
<<
line_num
<<
" "
<<
msg
<<
std
::
endl
;
<<
line_num
<<
" "
<<
msg
<<
std
::
endl
;
...
@@ -245,15 +254,16 @@ logger* logger::current_logger() {
...
@@ -245,15 +254,16 @@ logger* logger::current_logger() {
return
get_current_logger
();
return
get_current_logger
();
}
}
void
logger
::
log_static
(
int
level
,
const
std
::
string
&
class_name
,
void
logger
::
log_static
(
int
level
,
const
char
*
component
,
const
char
*
function_name
,
const
char
*
file_name
,
const
std
::
string
&
class_name
,
int
line_num
,
const
std
::
string
&
msg
)
{
const
char
*
function_name
,
const
char
*
file_name
,
int
line_num
,
const
std
::
string
&
msg
)
{
auto
ptr
=
get_current_logger
();
auto
ptr
=
get_current_logger
();
if
(
ptr
)
if
(
ptr
)
ptr
->
log
(
level
,
class_name
,
function_name
,
file_name
,
line_num
,
msg
);
ptr
->
log
(
level
,
component
,
class_name
,
function_name
,
file_name
,
line_num
,
msg
);
}
}
logger
::~
logger
()
{
logger
::~
logger
()
{
// nop
// nop
}
}
...
@@ -289,13 +299,13 @@ void logger::start() {
...
@@ -289,13 +299,13 @@ void logger::start() {
thread_
=
std
::
thread
{[
this
]
{
this
->
run
();
}};
thread_
=
std
::
thread
{[
this
]
{
this
->
run
();
}};
std
::
string
msg
=
"ENTRY log level = "
;
std
::
string
msg
=
"ENTRY log level = "
;
msg
+=
log_level_table
[
global_log_level
];
msg
+=
log_level_table
[
global_log_level
];
log
(
4
,
"caf::logger"
,
"run"
,
__FILE__
,
__LINE__
,
msg
);
log
(
4
,
"caf
"
,
"caf
::logger"
,
"run"
,
__FILE__
,
__LINE__
,
msg
);
# endif
# endif
}
}
void
logger
::
stop
()
{
void
logger
::
stop
()
{
# ifdef CAF_LOG_LEVEL
# ifdef CAF_LOG_LEVEL
log
(
4
,
"caf::logger"
,
"run"
,
__FILE__
,
__LINE__
,
"EXIT"
);
log
(
4
,
"caf
"
,
"caf
::logger"
,
"run"
,
__FILE__
,
__LINE__
,
"EXIT"
);
// an empty string means: shut down
// an empty string means: shut down
queue_
.
synchronized_enqueue
(
queue_mtx_
,
queue_cv_
,
new
event
{
""
});
queue_
.
synchronized_enqueue
(
queue_mtx_
,
queue_cv_
,
new
event
{
""
});
thread_
.
join
();
thread_
.
join
();
...
...
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