LCOV - code coverage report
Current view: top level - logging/test/apps - basic_functionality_example.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 52 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 55 0

            Line data    Source code
       1              : /**
       2              :  * @file logger.hpp logger interface definition
       3              :  *
       4              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  *
       8              :   cd build/logging
       9              :   make clean basic_functionality_example CXX_DEFINES=-DTRY_COMPILE=0
      10              : 
      11              : Run:
      12              :     install/logging/bin/basic_functionality_example
      13              :   or
      14              :     DUNEDAQ_ERS_VERBOSITY_LEVEL=2 install/logging/bin/basic_functionality_example
      15              :   or
      16              :     TRACE_LVLS=-1 install/logging/bin/basic_functionality_example
      17              :  */
      18              : 
      19              : #include <string>
      20              : #ifndef DUNEDAQ_PACKAGE_NAME            // this could/may be (tbd) set by the build system
      21              : #define DUNEDAQ_PACKAGE_NAME "Logging_" // becomes an ERS Qualifier
      22              : #endif
      23              : #include <ers/Issue.hpp>
      24              : #include <logging/Logging.hpp>
      25              : 
      26              : /** \def ers::File2 This is the base class for all file related issues.
      27              :  */
      28            0 : ERS_DECLARE_ISSUE(ers,                     // namespace
      29              :                   File2,                   // issue class name
      30              :                   ERS_EMPTY,               // no message
      31              :                   ((const char*)file_name) // single attribute
      32              : )
      33              : /** \def ers::CantOpenFile2 This issue is reported when a certain file can
      34              :  * not be opened by any reason.
      35              :  */
      36            0 : ERS_DECLARE_ISSUE_BASE(ers,           // namespace
      37              :                        CantOpenFile2, // issue class name
      38              :                        ers::File2,    // base class name
      39              :                        "Can not open \"" << file_name << "\" file arg2=" << arg2 << " arg3=" << arg3, // message
      40              :                        ((const char*)file_name),      // base class attributes
      41              :                        ((int)arg2)((const char*)arg3) // two attributes in this class
      42              : )
      43              : 
      44            0 : ERS_DECLARE_ISSUE(appframework,          // namespace
      45              :                   CommandNotRegistered2, // issue class name
      46              :                   "Command '" << command_name << "' does not have an entry in the CommandOrderMap!"
      47              :                               << " UserModules will receive this command in an unspecified order!",
      48              :                   ((const char*)command_name) // single attribute
      49              : )
      50              : 
      51            0 : ERS_DECLARE_ISSUE(appframework, // namespace
      52              :                   MyExit,       // issue class name
      53              :                   "exiting",
      54              :                   ERS_EMPTY // no attributes in this class
      55              : )
      56              : 
      57              : void
      58            0 : ex_thread(volatile const int* spinlock, int thread_idx)
      59              : {
      60            0 :   while (*spinlock)
      61              :     ; // The main program thread will clear this
      62              :       // once all thread are created and given a
      63              :       // chance to get here.
      64            0 :   for (auto uu = 0; uu < 5; ++uu)
      65            0 :     TLOG_DEBUG(8) << "tidx " << thread_idx << " fast LOG_DEBUG(8) #" << uu;
      66            0 : }
      67              : 
      68            0 : int main(/*int argc, char *argv[]*/)
      69              : {
      70              :   // FOR THIS EXAMPLE ONLY -- NOT NORMALLY NEEDED!! --v--v--v--v--v--v
      71              :   // activate TRACE memory buffer for debugging
      72            0 :   std::string tfile = "/tmp/trace_buffer_" + std::string(getenv("USER")) + "_basic";
      73            0 :   system(("rm -f " + tfile).c_str());
      74            0 :   setenv("TRACE_FILE", tfile.c_str(), 0);
      75            0 :   setenv("TRACE_LVLM", "-1", 0);
      76            0 :   setenv("TRACE_LVLS", "0xff", 0);
      77            0 :   TRACE_CNTL("reset");
      78              :   // --^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--
      79              : 
      80            0 :   setenv("DUNEDAQ_APPLICATION_NAME", "LOGGING_BASIC_FUN_APP", 0);
      81            0 :   dunedaq::logging::Logging::setup("test", "basic_functionality_example");
      82              : 
      83            0 :   TLOG_DEBUG(0) << "a message which doesn't go to the central logger";
      84            0 :   TLOG() << "another example of a message that doesn't go to the central logger";
      85            0 :   TLOG("MYNAME") << "yet another example -- messages are controllable via name+level";
      86              : 
      87              :   // ers::Message message(ERS_HERE,"Using TRACE_FILE="+tfile);
      88              :   // message.add_qualifier( "Logging_qual2" );
      89              :   // TLOG()  << message;
      90              : 
      91              :   //----------------------------------------
      92              : 
      93            0 :   ers::fatal(ers::CantOpenFile2(ERS_HERE, "My_Fatal_FileName - usually associated with throw or exit", 4, "four"));
      94              :   // ers::error( ers::Message( ERS_HERE, "this is ers::error( ers::Message( ERS_HERE, \"this is ...\" ) )" ) );
      95            0 :   ers::error(ers::CantOpenFile2(ERS_HERE, "My_Error_FileName", 5, "five"));
      96              : #if TRY_COMPILE & 0x1
      97              :   // see what happens with: make clean install CXX_DEFINES=-DTRY_COMPILE=1
      98              :   ers::error("error with just a string");
      99              : #endif
     100              :   // ers::warning( ers::CantOpenFile2(ERS_HERE,"My_Warn_FileName",6,"six") );
     101              :   // ers::warning( ers::Message(ERS_HERE,"My_Warn_Message with ignored macro param") );
     102              :   // ers::info(    ers::Message(ERS_HERE,"a specific TraceStreamer method with ers::Message isn't defined.") );
     103              : 
     104              :   //----------------------------------------
     105              : 
     106            0 :   TLOG("TEST1") << appframework::CommandNotRegistered2(ERS_HERE, "MyCommand");
     107            0 :   TLOG() << "LOG_LOG() stating LOG_DEBUG(n)'s follow -- they must be enabled via trace_cntl or DUNEDAQ_ERS_DEBUG_LEVEL";
     108              : 
     109              :   // TLOG_DEBUG(6)<< ers::Message(ERS_HERE,"A LOG_DEBUG(6) using ers::Message - The Logging has just been setup. ERS bug
     110              :   // - 1st DEBUG is always DEBUG_0");
     111            0 :   TLOG_DEBUG(6) << ers::CantOpenFile2(ERS_HERE, "My_Fatal_FileName_via_LOG_DEBUG_6", 7, "seven");
     112            0 :   TLOG_DEBUG(0) << "hello - debug level 0";
     113            0 :   TLOG_DEBUG(5) << "hello - debug level 5";
     114            0 :   TLOG_DEBUG(6) << "hello - debug level 6";
     115            0 :   TLOG_DEBUG(7) << ers::CantOpenFile2(ERS_HERE, "My_d07_FileName", 8, "eight");
     116              : 
     117            0 :   TLOG_DEBUG(8, "TEST2") << "testing name argument";
     118            0 :   TLOG_DEBUG(55) << "debug lvl 55";
     119            0 :   TLOG_DEBUG(56) << "debug lvl 56";
     120            0 :   TLOG_DEBUG(63) << "debug lvl 63";
     121            0 :   TLOG_DEBUG(64) << "debug lvl 64";
     122              : 
     123            0 :   TLOG() << "\ntshow follows:\n\n";
     124            0 :   system("TRACE_TIME_FMT='%Y-%b-%d %H:%M:%S,%%03d' TRACE_SHOW='%H%x%N %T %e %l %8L %m' trace_cntl show | trace_delta "
     125              :          "-ct 1 -d 1");
     126              : 
     127            0 :   TLOG() << "\nOne could try the same with DUNEDAQ_ERS_VERBOSITY_LEVEL=2 or 3\n";
     128              : 
     129            0 :   TLOG() << "\nNow, fast multithread...\n";
     130            0 :   const int kNumThreads = 5;
     131            0 :   std::thread threads[kNumThreads];
     132            0 :   int spinlock = 1;
     133            0 :   for (int uu = 0; uu < kNumThreads; ++uu)
     134            0 :     threads[uu] = std::thread(ex_thread, &spinlock, uu);
     135              : 
     136            0 :   usleep(20000);
     137            0 :   spinlock = 0;
     138              : 
     139            0 :   for (unsigned uu = 0; uu < kNumThreads; ++uu)
     140            0 :     threads[uu].join();
     141              : 
     142            0 :   TLOG() << "\ntshow follows:\n\n";
     143            0 :   system("TRACE_SHOW='%H%x%N %T %P %i %C %e %3L %R %m' trace_cntl show -c 25 | trace_delta -ct 1 -d 1");
     144              : 
     145            0 :   throw(appframework::MyExit(ERS_HERE));
     146              :   return (0);
     147            0 : } // main
        

Generated by: LCOV version 2.0-1