xref: /aosp_15_r20/external/clpeak/src/logger.cpp (revision 1cd03ba3888297bc945f2c84574e105e3ced3e34)
1 #include <logger.h>
2 #include <iomanip>
3 #include <sstream>
4 
logger(bool _enableXml,string _xmlFileName)5 logger::logger(bool _enableXml, string _xmlFileName) : enableXml(_enableXml)
6 {
7   if (enableXml)
8   {
9     xmlFile.open(_xmlFileName);
10     xw = new xmlWriter(xmlFile);
11     xmlFile.flush();
12   }
13 }
14 
~logger()15 logger::~logger()
16 {
17   if (enableXml)
18   {
19     xw->closeAll();
20     delete xw;
21     xmlFile.close();
22   }
23 }
24 
print(string str)25 void logger::print(string str)
26 {
27   cout << str;
28   cout.flush();
29 }
30 
print(double val)31 void logger::print(double val)
32 {
33   cout << setprecision(2) << fixed;
34   cout << val;
35   cout.flush();
36 }
37 
print(float val)38 void logger::print(float val)
39 {
40   cout << setprecision(2) << fixed;
41   cout << val;
42   cout.flush();
43 }
44 
print(int val)45 void logger::print(int val)
46 {
47   cout << val;
48   cout.flush();
49 }
50 
print(unsigned int val)51 void logger::print(unsigned int val)
52 {
53   cout << val;
54   cout.flush();
55 }
56 
xmlOpenTag(string tag)57 void logger::xmlOpenTag(string tag)
58 {
59   if (enableXml)
60   {
61     xw->openElt(tag.c_str());
62     xmlFile.flush();
63   }
64 }
65 
xmlAppendAttribs(string key,string value)66 void logger::xmlAppendAttribs(string key, string value)
67 {
68   if (enableXml)
69   {
70     xw->attr(key.c_str(), value.c_str());
71     xmlFile.flush();
72   }
73 }
74 
xmlAppendAttribs(string key,uint value)75 void logger::xmlAppendAttribs(string key, uint value)
76 {
77   if (enableXml)
78   {
79     stringstream ss;
80     ss << value;
81 
82     xw->attr(key.c_str(), ss.str().c_str());
83     xmlFile.flush();
84   }
85 }
86 
xmlSetContent(string value)87 void logger::xmlSetContent(string value)
88 {
89   if (enableXml)
90   {
91     xw->content(value.c_str());
92     xmlFile.flush();
93   }
94 }
95 
xmlSetContent(float value)96 void logger::xmlSetContent(float value)
97 {
98   if (enableXml)
99   {
100     stringstream ss;
101     ss << value;
102 
103     xw->content(ss.str().c_str());
104     xmlFile.flush();
105   }
106 }
107 
xmlCloseTag()108 void logger::xmlCloseTag()
109 {
110   if (enableXml)
111   {
112     xw->closeElt();
113     xmlFile.flush();
114   }
115 }
116 
xmlRecord(string tag,string value)117 void logger::xmlRecord(string tag, string value)
118 {
119   if (enableXml)
120   {
121     stringstream ss;
122     ss << value;
123 
124     xw->openElt(tag.c_str());
125     xw->content(ss.str().c_str());
126     xw->closeElt();
127     xmlFile.flush();
128   }
129 }
130 
xmlRecord(string tag,float value)131 void logger::xmlRecord(string tag, float value)
132 {
133   if (enableXml)
134   {
135     stringstream ss;
136     ss << value;
137 
138     xw->openElt(tag.c_str());
139     xw->content(ss.str().c_str());
140     xw->closeElt();
141     xmlFile.flush();
142   }
143 }
144