Newer
Older
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
*/
#include <corsika/logging/Logging.h>
TEST_CASE("Logging", "[Logging]") {
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
SECTION("top level functions using corsika logger") {
logging::info("This is an info message!");
logging::warn("This is a warning message!");
logging::debug("This is a debug message!");
logging::error("This is an error message!");
logging::critical("This is a critical error message!");
}
SECTION("create a specific logger") {
// create a logger manually
auto logger = logging::CreateLogger("loggerA");
// set a custom pattern for this logger
logger->set_pattern("[%n:%^%-8l%$] custom pattern: %v");
// and make sure we can log with this created object
logger->info("This is an info message!");
logger->warn("This is a warning message!");
logger->debug("This is a debug message!");
logger->error("This is an error message!");
logger->critical("This is a critical error message!");
// get a reference to the logger using Get
auto other = logging::GetLogger("loggerA");
// and make sure we can use this other reference to log
other->info("This is an info message!");
other->warn("This is a warning message!");
other->debug("This is a debug message!");
other->error("This is an error message!");
other->critical("This is a critical error message!");
}
SECTION("get a new logger") {
// get a reference to an unknown logger
auto logger = logging::GetLogger("loggerB");
// and make sure we can log with this created object
logger->info("This is an info message!");
logger->warn("This is a warning message!");
logger->debug("This is a debug message!");
logger->error("This is an error message!");
logger->critical("This is a critical error message!");
}
SECTION("test log level") {
// set the default log level
logging::SetDefaultLevel(logging::level::critical);
// and make sure we can log with this created object
logging::info("This should NOT be printed!");
logging::warn("This should NOT be printed!");
logging::debug("This should NOT be printed!");
logging::error("This should NOT be printed!");
logging::critical("This SHOULD BE printed!!");
// and reset it for the next tests
logging::SetDefaultLevel(logging::level::debug);
}
SECTION("test macro style printing") {
// these print with the "corsika" logger
C8LOG_INFO("This is a macro info msg!");
C8LOG_DEBUG("This is a macro debug msg!");
C8LOG_ERROR("This is a macro error msg!");
C8LOG_CRITICAL("This is a macro critical msg!");
// get a reference to an unknown logger
auto logger = logging::GetLogger("loggerD");
// these print with the "loggerD" logger
C8LOG_LOGGER_INFO(logger, "This is a macro info msg!");
C8LOG_LOGGER_WARN(logger, "This is a macro warn msg!");
}