Skip to content
Snippets Groups Projects

Wolf logging macro

Merged Jeremie Deray requested to merge wolf_logging into master
1 unresolved thread

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 :

Screenshot_from_2016-11-04_17_47_20

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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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 three shared_ptr to H, T and M, and each of these has a weak_ptr to P.
    • 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 to P when I am constructing P:
        • H::problem_ptr = shared_from_this(); does not work!
    • Solution: make constructor P() private, and write a factory method P::create() as in the code above
      • New Issue: To construct a ProblemPtr (aka shared_ptr<P>), I cannot use make_shared<P>, because it needs to call P() , and it is private:
        • ProblemPtr p = make_shared<P>(_frame_structure) does not work!
        • Solution: I call the shared_ptr constructor with the new syntax and not the make_shared:
          • ProblemPtr p(new Problem(_frame_structure)); works!
  • Please register or sign in to reply
  • 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 ?
    • Indeed, only useful for the examples.

      If we make other kind of tests, it will also be useful. Usually, we use it for specifying absolute path names to configuration files, most commonly YAML files.

    • Please register or sign in to reply
  • Done option(_WOLF_TRACE "Enable wolf tracing macro" ON) in CMakeLists, and put debug options in 'debug' mode. But no debug info after issuing WOLF_DEBUG(...). What am I doing wrong? I even added option(_WOLF_DEBUG "Enable wolf debugging macro" ON), but no luck either.

  • Author Developer

    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 posterior couts:

      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.

  • Please register or sign in to reply
    Loading