Wolf logging macro
Notice: This PR is only about simple wolf logging macro as described below and do not implement any data logging as this topic as to be discussed. A data logging draft class is implemented on branch wolf_data_logging.
Enable logging macro using third-party spdlog (MIT license) :
WOLF_INFO
WOLF_WARN
WOLF_ERROR
-
WOLF_DEBUG
(enabled only if compiled in debug) -
WOLF_TRACE
(which is the same as WOLF_DEBUG_HERE but enabled/disabled at compile time)
Trace logging is enabled/disabled from the src/CMakeLists.txt
option
option(_WOLF_TRACE "Enable wolf tracing macro" OFF)
test_wolf_logging.cpp
shows the following:
WOLF_INFO("test info ", 5, " ", 0.123);
WOLF_WARN("test warn ", 5, " ", 0.123);
WOLF_ERROR("test error ", 5, " ", 0.123);
WOLF_TRACE("test trace ", 5, " ", 0.123);
WOLF_DEBUG("test debug ", 5, " ", 0.123);
Which, full feature enabled, produces :
The log pattern is :
[thread id][hour:min:sec.nanosec][log type] log-content
The TRACE
log pattern is :
[thread id][hour:min:sec.nanosec][log type][$file l#$line : $function] log-content
Merge request reports
Activity
Set this PR to WIP.
The question is, do we actually want to be able to enable/disableWOLF_DEBUG
manually (at run-time) knowing that currently, if debug is disabled, it has an overhead cost of calling a function and testing a boolean ?? A zero cost might be preferable with the counter-part of not being able to manually enable/disable the debug macro. @jsola What do you think ?Added 1 commit:
- fffcaf17 - add proper trace & set trace color green+bold
Mentioned in commit d4222064
- src/singleton.h 0 → 100644
9 #define WOLF_SINGLETON_H_ 10 11 #include <memory> 12 13 namespace wolf { 14 namespace internal { 15 16 /** 17 * \brief A thread-safer Singleton implementation with 18 * argument forwarding. 19 **/ 20 template <class T> 21 class Singleton 22 { 23 /** 24 * \brief Custom deleter to by-pass private destructor issue. Is your issue similar to this? In
problem.cpp
:ProblemPtr Problem::create(FrameStructure _frame_structure) { ProblemPtr p(new Problem(_frame_structure)); // We use `new` and not `make_shared` since the Problem constructor is private and cannot be passes to `make_shared`. p->setup(); return p->shared_from_this(); }
Explanation:
- Problem (in short,
P
) has threeshared_ptr
toH
,T
andM
, and each of these has aweak_ptr
toP
. - For the sake of a good user API, I want all these pointers to be valid just after creating
P
. - At construction time,
shared_from_this()
does not work- Therefore, I cannot link
H
,T
,M
toP
when I am constructingP
:-
H::problem_ptr = shared_from_this();
does not work!
-
- Therefore, I cannot link
- Solution: make constructor
P()
private, and write a factory methodP::create()
as in the code above- New Issue: To construct a
ProblemPtr
(akashared_ptr<P>
), I cannot usemake_shared<P>
, because it needs to callP()
, and it is private:-
ProblemPtr p = make_shared<P>(_frame_structure)
does not work! - Solution: I call the
shared_ptr
constructor with thenew
syntax and not themake_shared
:-
ProblemPtr p(new Problem(_frame_structure));
works!
-
-
- New Issue: To construct a
- Problem (in short,
10 10 11 # Some wolf compilation options 12 11 13 IF(CMAKE_BUILD_TYPE MATCHES DEBUG) 12 14 set(_WOLF_DEBUG true) 13 #list(APPEND WOLF_COMPILE_OPTIONS _WOLF_DEBUG) 14 15 ENDIF() 15 16 17 option(_WOLF_TRACE "Enable wolf tracing macro" OFF) 16 18 17 19 option(BUILD_EXAMPLES "Build examples" ON) 18 20 21 22 19 23 # Does this has any other interest 20 24 # but for the examples ? You need to compile in debug to have the debug macro enabled. If you did then maybe cmake is referring to a cmake cache file rather than the actual cmakelists. You can delete the build directory and build from scratch to make sure. If after all that there is still nothing then we will check tomorrow.
OK. Now it does this. This is the end of a main() in a test:
[...] problem->print(); WOLF_DEBUG("hola ", 1, " nanu " , 2) return 0; }
and this is the outcome of the
DEBUG
macro, surrounded by previous and posteriorcout
s:F7 Estim, ts=4, x = ( -1.7e-17 0 6.3 ) C13 -> S1 Map ----------------------------------------- [36m[4260977924346863084][23:54:57.933986000][debug] hola 1 nanu 2 [00mdestructed -P destructed -M destructed -T destructed -F7
It seems that
- some weird initial character is bing printed
- there is some weird info being printed
- a final
endl
is missing.
FYI: I am on my Mac. Should try on Ubuntu and see if these oddities are consistent there.
No hurry for this though.