LCOV - code coverage report
Current view: top level - include/utils - Logger.h (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 18 18 100.0 %
Date: 2025-07-30 13:02:48 Functions: 60 80 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include "MooseError.h"
      13             : 
      14             : /**
      15             :  * Keeps the error and warning messages
      16             :  */
      17             : class Logger
      18             : {
      19             : public:
      20             :   Logger();
      21             :   virtual ~Logger();
      22             : 
      23             :   enum EMessageType
      24             :   {
      25             :     ERROR = 0,
      26             :     WARNING = 1
      27             :   };
      28             : 
      29             :   /**
      30             :    * Add a message to the log
      31             :    *
      32             :    * @param type The type of the message
      33             :    */
      34             :   template <typename... Args>
      35         335 :   void add(EMessageType type, Args &&... args)
      36             :   {
      37         335 :     std::ostringstream oss;
      38         319 :     moose::internal::mooseStreamAll(oss, args...);
      39             : 
      40         670 :     Logger::Message * msg = new Logger::Message(type, oss.str());
      41         335 :     _msgs.push_back(msg);
      42             : 
      43         335 :     switch (type)
      44             :     {
      45         289 :       case ERROR:
      46         289 :         _n_errors++;
      47         289 :         break;
      48          46 :       case WARNING:
      49          46 :         _n_warnings++;
      50          46 :         break;
      51             :     }
      52         335 :   }
      53             : 
      54             :   /**
      55             :    * Calls mooseError if there are any logged errors
      56             :    */
      57             :   void emitLoggedErrors() const;
      58             : 
      59             :   /**
      60             :    * Calls mooseWarning if there are any logged warnings
      61             :    */
      62             :   void emitLoggedWarnings() const;
      63             : 
      64             :   /**
      65             :    * Return the number of errors
      66             :    *
      67             :    * @return The number of errors in this log
      68             :    */
      69             :   unsigned int getNumberOfErrors() const;
      70             : 
      71             :   /**
      72             :    * Return the number of warnings
      73             :    *
      74             :    * @return The number of warnings in this log
      75             :    */
      76             :   unsigned int getNumberOfWarnings() const;
      77             : 
      78             : protected:
      79             :   /**
      80             :    * Simple data structure to hold the messages
      81             :    */
      82          59 :   class Message
      83             :   {
      84             :   public:
      85         335 :     Message(EMessageType type, const std::string & msg)
      86         335 :     {
      87         335 :       _type = type;
      88             :       _msg = msg;
      89         335 :     }
      90             : 
      91             :     /// The type of the message
      92             :     EMessageType _type;
      93             :     /// The text of the message
      94             :     std::string _msg;
      95             :   };
      96             : 
      97             :   /// The number of errors
      98             :   unsigned int _n_errors;
      99             :   /// The number of warnings
     100             :   unsigned int _n_warnings;
     101             :   /// The list of logged messages
     102             :   std::vector<Message *> _msgs;
     103             : };

Generated by: LCOV version 1.14