Skip to content

Commit

Permalink
Merge pull request #27 from DUNE-DAQ/ron/issue_26_TLOG_issue_bug
Browse files Browse the repository at this point in the history
Ron/issue 26 tlog issue bug
  • Loading branch information
ron003 authored Apr 9, 2024
2 parents 118aea3 + f07019e commit 736a5fe
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ daq_add_application( performance performance.cxx TEST LINK_LIBRARIES logging )
daq_add_application( six_streams six_streams.cxx TEST LINK_LIBRARIES logging )
daq_add_application( debug_speed debug_speed.cxx TEST LINK_LIBRARIES logging )
daq_add_application( multithreaded_warning_log multithreaded_warning_log.cxx TEST LINK_LIBRARIES logging )
daq_add_application( log_progress_update log_progress_update.cxx TEST LINK_LIBRARIES logging )


daq_install()
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Conventions and best practices for ERS issues in the DUNE DAQ software can be fo

The above referenced conventions and best practices does not cover the use of the TRACE macros.

The TLOG() macro should used in cases similar to ers::info with the following 2 distinctions: 1) unstructed (non-ers::Issue) messages can be used and 2) logging will remain local, i.e. stdout only and not to a central/network logging facility.
The TLOG() macro should be used in cases similar to ers::info with the following 2 distinctions: 1) unstructed (non-ers::Issue) messages can be used and 2) logging will remain local, i.e. stdout only and not to a central/network logging facility.

The TLOG_DEBUG(lvl) is to be used for messages which will be selectively enabled or disabled for debugging purposes. The lvl can be an arbitrary integer between 0 and 55.

Expand Down
12 changes: 8 additions & 4 deletions include/logging/internal/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
# define ERS_DECLARE_ISSUE_BASE( namespace_name, class_name, base_class_name, message_, base_attributes, attributes ) \
__ERS_DECLARE_ISSUE_BASE__( namespace_name, class_name, base_class_name, message_, base_attributes, attributes ) \
__ERS_DEFINE_ISSUE_BASE__( inline, namespace_name, class_name, base_class_name, message_, base_attributes, attributes ) \
static inline TraceStreamer& operator<<(TraceStreamer& x, const namespace_name::class_name &r) \
namespace namespace_name { \
static inline TraceStreamer& operator<<(TraceStreamer& x, const class_name &r) \
{if (x.do_m) {\
x.line_=r.context().line_number(); x.msg_append( r.message().c_str() );\
/* MAY NEED TO APPEND CHAINED ISSUE??? */ \
Expand All @@ -57,13 +58,15 @@
x.do_s = 0; \
} \
return x; \
}
} \
}

# undef ERS_DECLARE_ISSUE
# define ERS_DECLARE_ISSUE( namespace_name, class_name, message_, attributes ) \
__ERS_DECLARE_ISSUE_BASE__( namespace_name, class_name, ers::Issue, ERS_EMPTY message_, ERS_EMPTY, attributes ) \
__ERS_DEFINE_ISSUE_BASE__( inline, namespace_name, class_name, ers::Issue, ERS_EMPTY message_, ERS_EMPTY, attributes ) \
static inline TraceStreamer& operator<<(TraceStreamer& x, const namespace_name::class_name &r) \
namespace namespace_name { \
static inline TraceStreamer& operator<<(TraceStreamer& x, const class_name &r) \
{if (x.do_m) {\
x.line_=r.context().line_number(); x.msg_append( r.message().c_str() );\
/* MAY NEED TO APPEND CHAINED ISSUE??? */ \
Expand All @@ -75,6 +78,7 @@
x.do_s = 0; \
} \
return x; \
}
} \
}

#endif // LOGGING_INCLUDE_LOGGING_INTERNAL_MACRO_HPP_
4 changes: 2 additions & 2 deletions test/apps/basic_functionality_example.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int main(/*int argc, char *argv[]*/)
TLOG_DEBUG(64) << "debug lvl 64";

TLOG() << "\ntshow follows:\n\n";
system( "TRACE_TIME_FMT=\"%Y-%b-%d %H:%M:%S,%%03d\" TRACE_SHOW=\"%H%x%N %T %e %l %L %m\" trace_cntl show | trace_delta -ct 1 -d 1" );
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 -ct 1 -d 1" );

TLOG() << "\nOne could try the same with DUNEDAQ_ERS_VERBOSITY_LEVEL=2 or 3\n";

Expand All @@ -138,7 +138,7 @@ int main(/*int argc, char *argv[]*/)
threads[uu].join();

TLOG() << "\ntshow follows:\n\n";
system( "TRACE_SHOW=\"%H%x%N %T %P %i %C %e %L %R %m\" trace_cntl show -c 25 | trace_delta -ct 1 -d 1" );
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" );

throw( appframework::MyExit(ERS_HERE) );
return (0);
Expand Down
62 changes: 62 additions & 0 deletions test/apps/log_progress_update.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef DUNEDAQ_PACKAGE_NAME // this could/may be (tbd) set by the build system
# define DUNEDAQ_PACKAGE_NAME "Logging_" // becomes an ERS Qualifier
#endif
#include <logging/Logging.hpp> // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
#include <ers/Issue.hpp>
#include <vector>

ERS_DECLARE_ISSUE(appfwk, ///< Namespace
GeneralDAQModuleIssue, ///< Issue class name
" DAQModule: " << name, ///< Message
((std::string)name) ///< Message parameters
)

ERS_DECLARE_ISSUE_BASE(logging,
ProgressUpdate,
appfwk::GeneralDAQModuleIssue,
message,
((std::string)name),
((std::string)message))

using namespace logging;

std::ostream&
operator<<(std::ostream& t, std::vector<int> ints)
{
t << "{";
bool first = true;
for (auto& i : ints) {
if (!first)
t << ", ";
first = false;
t << i;
}
return t << "}";
}

int main(/*int argc, char *argv[]*/)
{
setenv("DUNEDAQ_APPLICATION_NAME","LOGGING_PROGRESS_APP",0);
dunedaq::logging::Logging::setup(); // not strictly needed -- checks/establishes a default env.

std::atomic<uint64_t> m_generated_tot{ 7 };
std::vector<int> theList{1,2,3};
std::ostringstream oss_prog;
TLOG() << "start";
oss_prog << "Generated list #" << m_generated_tot.load() << " with contents " << theList
<< " and size " << theList.size() << ". ";

std::cout << typeid(ProgressUpdate).name() << "\n\n";

TLOG() << static_cast<logging::ProgressUpdate>(ProgressUpdate(ERS_HERE, "someName1", oss_prog.str()));

#if 1
TLOG_DEBUG() << ProgressUpdate(ERS_HERE, "someName2", oss_prog.str());
std::cout << ProgressUpdate(ERS_HERE, "someName3", oss_prog.str()) << '\n';

TLOG_DEBUG() << ProgressUpdate(ERS_HERE, "someName4", oss_prog.str());
TLOG_DEBUG() << ProgressUpdate(ERS_HERE, "someName5", oss_prog.str());
#endif

return 0;
}
2 changes: 1 addition & 1 deletion test/apps/multithreaded_warning_log.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ example: %s
#include <stdlib.h> // rand_r, RAND_MAX
#include <vector>
#include <thread>
#define JUST_ERS 1
#define JUST_ERS 0
#if JUST_ERS
# include <ers/ers.hpp>
#else
Expand Down

0 comments on commit 736a5fe

Please sign in to comment.