• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-Sn / opensn / 20185909776

12 Dec 2025 06:55PM UTC coverage: 74.333% (+0.3%) from 74.037%
20185909776

push

github

web-flow
Merge pull request #859 from wdhawkins/td_source_driver

Adding time-dependent solver and time-dependent sources

367 of 398 new or added lines in 23 files covered. (92.21%)

113 existing lines in 28 files now uncovered.

18610 of 25036 relevant lines covered (74.33%)

68947552.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/framework/logging/log.h
1
// SPDX-FileCopyrightText: 2024 The OpenSn Authors <https://open-sn.github.io/opensn/>
2
// SPDX-License-Identifier: MIT
3

4
#pragma once
5

6
#include "framework/logging/log_stream.h"
7
#include "framework/logging/log_exceptions.h"
8
#include <utility>
9
#include <vector>
10
#include <memory>
11

12
namespace opensn
13
{
14

15
/**
16
 * Object for controlling logging.
17
 *
18
 * ## Part A: Output logs
19
 * There are three levels of verbosity in OpenSn: Zero(Default), One and Two.
20
 * These can be set on the command line via the switch -v followed by a
21
 * space and the number for the verbosity (0,1 or 2).
22
 *
23
 * \code
24
 * ./opensn InputFile.py -v 1
25
 * \endcode
26
 *
27
 * Printing a log under the auspices of a verbosity level again has
28
 * numerous options. Firstly, any log can be a normal log, a warning
29
 * or an error. Secondly, a log can be either location 0 or all the locations
30
 * in a parallel process environment. The log option enums defined under
31
 * LOG_LVL are
32
 *  - LOG_0,                      Used only for location 0
33
 *  - LOG_0WARNING,               Warning only for location 0
34
 *  - LOG_0ERROR,                 Error only for location 0
35
 *  - LOG_0VERBOSE_0,             Default verbosity level
36
 *  - LOG_0VERBOSE_1,             Used only if verbosity level equals 1
37
 *  - LOG_0VERBOSE_2,             Used only if verbosity level equals 2
38
 *  - LOG_ALL,                    Verbose level 0 all locations
39
 *  - LOG_ALLWARNING,             Warning for any location
40
 *  - LOG_ALLERROR,               Error for any location
41
 *  - LOG_ALLVERBOSE_0,     Default verbosity level
42
 *  - LOG_ALLVERBOSE_1,     Used only if verbosity level equals 1
43
 *  - LOG_ALLVERBOSE_2,     Used only if verbosity level equals 2
44
 *
45
 * A log can be made by first connecting code with the logger. This is done
46
 * by including the log header and then defining an extern reference to the
47
 * global object.
48
 *
49
 * \code
50
 * #include "framework/logging/log.h"
51
 * extern Logger& opensn::log;
52
 * \endcode
53
 *
54
 * A log is then written inside a piece of code as follows:
55
 *
56
 * \code
57
 * void PrintSomethingToLog()
58
 * {
59
 *   opensn::log.Log() << "This is printed on location 0 only";
60
 *   opensn::log.Log0Warning() << "This is a warning";
61
 *   opensn::log.Log0Error() << "This is an error";
62
 * }
63
 * \endcode
64
 *
65
 * \verbatim
66
 * [0]  This is printed on location 0 only
67
 * [0]  **** WARNING **** This is a warning
68
 * [0]  ****  ERROR  **** This is an error
69
 * \endverbatim
70
 */
71
class Logger
72
{
73
public:
74
  /// Logging level
75
  enum LOG_LVL
76
  {
77
    LOG_0 = 1,             ///< Used only for location 0
78
    LOG_0WARNING = 2,      ///< Warning only for location 0
79
    LOG_0ERROR = 3,        ///< Error only for location 0
80
    LOG_0VERBOSE_0 = 4,    ///< Default verbosity level
81
    LOG_0VERBOSE_1 = 5,    ///< Used only if verbosity level equals 1
82
    LOG_0VERBOSE_2 = 6,    ///< Used only if verbosity level equals 2
83
    LOG_ALL = 7,           ///< Verbose level 0 all locations
84
    LOG_ALLWARNING = 8,    ///< Warning for any location
85
    LOG_ALLERROR = 9,      ///< Error for any location
86
    LOG_ALLVERBOSE_0 = 10, ///< Default verbosity level
87
    LOG_ALLVERBOSE_1 = 11, ///< Used only if verbosity level equals 1
88
    LOG_ALLVERBOSE_2 = 12  ///< Used only if verbosity level equals 2
89
  };
90

91
  Logger(const Logger&) = delete;
92
  Logger& operator=(const Logger&) = delete;
93

94
  void SetVerbosity(unsigned int level) { verbosity_ = std::min(level, 2U); }
95
  unsigned int GetVerbosity() const { return verbosity_; }
96
  LogStream Log(LOG_LVL level = LOG_0);
97
  LogStream Log0() { return Log(LOG_0); }
98
  LogStream Log0Warning() { return Log(LOG_0WARNING); }
2,532✔
99
  LogStream Log0Error() { return Log(LOG_0ERROR); }
100
  LogStream Log0Verbose0() { return Log(LOG_0VERBOSE_0); }
101
  LogStream Log0Verbose1() { return Log(LOG_0VERBOSE_1); }
17,986✔
102
  LogStream Log0Verbose2() { return Log(LOG_0VERBOSE_2); }
64✔
103
  LogStream LogAll() { return Log(LOG_ALL); }
104
  LogStream LogAllWarning() { return Log(LOG_ALLWARNING); }
105
  LogStream LogAllError() { return Log(LOG_ALLERROR); }
106
  LogStream LogAllVerbose0() { return Log(LOG_ALLVERBOSE_0); }
107
  LogStream LogAllVerbose1() { return Log(LOG_ALLVERBOSE_1); }
108
  LogStream LogAllVerbose2() { return Log(LOG_ALLVERBOSE_2); }
1,565✔
109

110
private:
111
  Logger() = default;
112

113
  DummyStream dummy_stream_;
114
  unsigned int verbosity_{0};
115

116
public:
117
  static Logger& GetInstance() noexcept
118
  {
119
    static Logger instance;
962✔
120
    return instance;
960,092✔
121
  }
13✔
122
};
8✔
123

23,195✔
124
} // namespace opensn
777✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc