LCOV - code coverage report
Current view: top level - ers/src - StandardStreamOutput.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 50.0 % 48 24
Test Date: 2026-10-11 15:05:20 Functions: 57.1 % 7 4

            Line data    Source code
       1              : /*
       2              :  * DUNE DAQ modification notice:
       3              :  * This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
       4              :  * Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
       5              :  * Renamed since fork: yes (from src/StandardStreamOutput.cxx to src/StandardStreamOutput.cpp).
       6              :  *
       7              :  * Original copyright:
       8              :  * Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
       9              :  * Licensed under the Apache License, Version 2.0.
      10              :  */
      11              : 
      12              : /*
      13              :  *  StandardStreamOutput.cxx
      14              :  *  ers
      15              :  *
      16              :  *  Created by Serguei Kolos on 02.08.07.
      17              :  *  Copyright 2007 CERN. All rights reserved.
      18              :  *
      19              :  */
      20              : #include <iomanip>
      21              : 
      22              : #include <ers/Issue.hpp>
      23              : #include <ers/Severity.hpp>
      24              : #include <ers/StandardStreamOutput.hpp>
      25              : #include <ers/internal/Util.hpp>
      26              : 
      27              : #include <boost/algorithm/string.hpp>
      28              : 
      29              : #define FIELD_SEPARATOR "\n\t"
      30              : 
      31              : namespace {
      32              : std::function<std::string(const ers::Issue& issue)>
      33           78 : getTimeFormatter()
      34              : {
      35          156 :   static std::string format = ers::read_from_environment("DUNEDAQ_ERS_TIMESTAMP_FORMAT", "%Y-%b-%d %H:%M:%S");
      36              : 
      37          156 :   static const std::string precision = ers::read_from_environment("DUNEDAQ_ERS_TIMESTAMP_PRECISION", "MILLI");
      38              : 
      39           78 :   static const bool isUTC = ::getenv("DUNEDAQ_ERS_TIMESTAMP_UTC");
      40              : 
      41           78 :   if (boost::algorithm::ifind_first(precision, "NANO")) {
      42            0 :     return [](const ers::Issue& issue) { return issue.time<std::chrono::nanoseconds>(format, isUTC); };
      43              :   }
      44              : 
      45           78 :   if (boost::algorithm::ifind_first(precision, "MICRO")) {
      46            0 :     return [](const ers::Issue& issue) { return issue.time<std::chrono::microseconds>(format, isUTC); };
      47              :   }
      48              : 
      49           78 :   if (boost::algorithm::ifind_first(precision, "MILLI")) {
      50         1164 :     return [](const ers::Issue& issue) { return issue.time<std::chrono::milliseconds>(format, isUTC); };
      51              :   }
      52              : 
      53            0 :   return [](const ers::Issue& issue) { return issue.time(format, isUTC); };
      54              : }
      55              : 
      56              : const auto formatted_time = getTimeFormatter();
      57              : }
      58              : 
      59              : std::ostream&
      60         1082 : ers::StandardStreamOutput::println(std::ostream& out, const Issue& issue, int verbosity)
      61              : {
      62         1082 :   print(out, issue, verbosity);
      63         1082 :   out << std::endl;
      64         1082 :   return out;
      65              : }
      66              : 
      67              : std::ostream&
      68         1086 : ers::StandardStreamOutput::print(std::ostream& out, const Issue& issue, int verbosity)
      69              : {
      70         1086 :   if (verbosity > -3) {
      71         1086 :     out << formatted_time(issue) << " ";
      72              :   }
      73              : 
      74         1086 :   if (verbosity > -2) {
      75         1086 :     out << ers::to_string(issue.severity()) << " ";
      76              :   }
      77              : 
      78         1086 :   if (verbosity > -1) {
      79         1086 :     out << "[" << issue.context().position(verbosity) << "] ";
      80              :   }
      81              : 
      82         1086 :   out << issue.message();
      83              : 
      84         1086 :   if (verbosity > 1) {
      85            0 :     out << FIELD_SEPARATOR << "Parameters = ";
      86            0 :     for (ers::string_map::const_iterator it = issue.parameters().begin(); it != issue.parameters().end(); ++it) {
      87            0 :       out << "'" << it->first << "=" << it->second << "' ";
      88              :     }
      89              : 
      90            0 :     out << FIELD_SEPARATOR << "Qualifiers = ";
      91            0 :     for (std::vector<std::string>::const_iterator it = issue.qualifiers().begin(); it != issue.qualifiers().end();
      92            0 :          ++it) {
      93            0 :       out << "'" << *it << "' ";
      94              :     }
      95              :   }
      96              : 
      97            0 :   if (verbosity > 2) {
      98            0 :     out << FIELD_SEPARATOR << "host = " << issue.context().host_name() << FIELD_SEPARATOR
      99            0 :         << "user = " << issue.context().user_name() << " (" << issue.context().user_id() << ")" << FIELD_SEPARATOR
     100            0 :         << "process id = " << issue.context().process_id() << FIELD_SEPARATOR
     101            0 :         << "thread id = " << issue.context().thread_id() << FIELD_SEPARATOR << "process wd = " << issue.context().cwd();
     102              :   }
     103              : 
     104            0 :   if (verbosity > 3) {
     105            0 :     std::ios_base::fmtflags flags(out.flags());
     106              : 
     107            0 :     out << std::left;
     108            0 :     std::vector<std::string> stack = issue.context().stack();
     109            0 :     out << FIELD_SEPARATOR << "stack trace of the crashing thread:";
     110            0 :     for (size_t i = 0; i < stack.size(); i++) {
     111            0 :       out << FIELD_SEPARATOR << "  #" << std::setw(3) << i << stack[i];
     112              :     }
     113              :     // restore the original state
     114            0 :     out.flags(flags);
     115            0 :   }
     116              : 
     117         1086 :   if (issue.cause()) {
     118            4 :     out << FIELD_SEPARATOR << "was caused by: " << *issue.cause();
     119              :   }
     120              : 
     121         1086 :   return out;
     122              : }
        

Generated by: LCOV version 2.0-1