preCICE v3.1.2
Loading...
Searching...
No Matches
LogConfiguration.cpp
Go to the documentation of this file.
5
6namespace precice::config {
7
9 xml::XMLTag &parent)
10{
11 // We do default initialization here, so logging will be initialized
12 // as soon as possible and also if there is no <log> tag.
14
15 using namespace xml;
16 XMLTag tagLog(*this, "log", XMLTag::OCCUR_NOT_OR_ONCE);
17 tagLog.setDocumentation("Configures logging sinks based on Boost log.");
18
19 auto attrLogEnabled = makeXMLAttribute("enabled", true)
20 .setDocumentation("Enables the creation of log sinks. "
21 "Disable sinks if you prefer to handle preCICE logs in your application using boost.log.");
22
23 tagLog.addAttribute(attrLogEnabled);
24
25 XMLTag tagSink(*this, "sink", XMLTag::OCCUR_ARBITRARY);
26 tagSink.setDocumentation("Contains the configuration of a single log sink, which allows fine grained control of what to log where. "
27 "Available attributes in filter and format strings are `%TimeStamp%`, `%Runtime%`, `%Severity%`, `%ColorizedSeverity%`, `%File%`, `%Line%`, `%Function%`, `%Module%`, `%Rank%`, and `%Participant%`. "
28 "The boolean attribute `%preCICE%` is `true` for all log entries originating from preCICE.");
29 auto attrType = XMLAttribute<std::string>("type")
30 .setDocumentation("The type of sink.")
31 .setOptions({"stream", "file"})
33 tagSink.addAttribute(attrType);
34
35 auto attrOutput = XMLAttribute<std::string>("output")
36 .setDocumentation("Depends on the type of the sink. For streams, this can be stdout or stderr. For files, this is the filename.")
38 tagSink.addAttribute(attrOutput);
39
40 auto attrFormat = XMLAttribute<std::string>("format")
41 .setDocumentation("Boost Log Format String")
43 tagSink.addAttribute(attrFormat);
44
45 auto attrFilter = XMLAttribute<std::string>("filter")
46 .setDocumentation("Boost Log Filter String")
48 tagSink.addAttribute(attrFilter);
49
50 auto attrEnabled = makeXMLAttribute("enabled", true)
51 .setDocumentation("Enables the sink");
52 tagSink.addAttribute(attrEnabled);
53
54 tagLog.addSubtag(tagSink);
55 parent.addSubtag(tagLog);
56}
57
59 const xml::ConfigurationContext &context,
60 xml::XMLTag & tag)
61{
63
64 if (tag.getName() == "sink") {
66 config.setOption("type", tag.getStringAttributeValue("type"));
67 config.setOption("output", tag.getStringAttributeValue("output"));
68 config.setOption("filter", tag.getStringAttributeValue("filter"));
69 config.setOption("format", tag.getStringAttributeValue("format"));
70 config.setEnabled(tag.getBooleanAttributeValue("enabled"));
71 _logconfig.push_back(config);
72 }
73}
74
83
84} // namespace precice::config
#define PRECICE_TRACE(...)
Definition LogMacros.hpp:95
precice::logging::LoggingConfiguration _logconfig
virtual void xmlEndTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &tag)
Callback at end of XML tag and at end of subtag.
virtual void xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &tag)
Callback at begin of XML tag.
XMLAttribute & setDocumentation(std::string documentation)
Sets a documentation string for the attribute.
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:31
std::string getStringAttributeValue(const std::string &name, std::optional< std::string > default_value=std::nullopt) const
Definition XMLTag.cpp:142
bool getBooleanAttributeValue(const std::string &name, std::optional< bool > default_value=std::nullopt) const
Definition XMLTag.cpp:155
const std::string & getName() const
Returns name (without namespace).
Definition XMLTag.hpp:153
const std::string & getFullName() const
Returns full name consisting of xml namespace + ":" + name.
Definition XMLTag.hpp:170
XMLTag & addSubtag(const XMLTag &tag)
Adds an XML tag as subtag by making a copy of the given tag.
Definition XMLTag.cpp:41
void setupLogging(LoggingConfiguration configs, bool enabled)
Configures the logging from a LoggingConfiguration.
T push_back(T... args)
Holds the configuration for one logging backend (sink) and takes care of default values.
void setEnabled(bool enabled)
Sets weather the sink is enabled or disabled.
void setOption(std::string key, std::string value)
Sets on option, overwrites default values.
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:24