Skip to content

Commit 5500f5e

Browse files
committed
Incres usage of logging framework
1 parent 33d8a82 commit 5500f5e

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

lib/ippattr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "variant.h"
77

88
#include <cstdint>
9-
#include <iostream>
109
#include <map>
1110
#include <string>
1211

lib/ippdiscovery.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <chrono>
77
#include <cstring>
8-
#include <iostream>
98
#include <set>
109
#include <sstream>
1110
#include <stdexcept>
@@ -359,7 +358,7 @@ void IppDiscovery::discover()
359358
}
360359
catch(const std::exception& e)
361360
{
362-
std::cerr << e.what();
361+
DBG(<< e.what());
363362
}
364363

365364
DBG(<< "------------");

lib/ippmsg.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "ippmsg.h"
2-
3-
#include <iostream>
2+
#include "log.h"
43

54
uint32_t IppMsg::_reqId=1;
65

@@ -31,10 +30,8 @@ IppMsg::IppMsg(Bytestream& msg)
3130
}
3231
else if(currentAttrType == IppTag::UnsupportedAttrs)
3332
{
34-
#ifndef FUZZ // Too much spam for fuzzing
35-
std::cerr << "WARNING: unsupported attrs reported: " << std::endl
36-
<< attrs.toJSON().dump();
37-
#endif
33+
WARN(<< "WARNING: unsupported attrs reported: " << std::endl
34+
<< attrs.toJSON().dump());
3835
}
3936

4037
if(msg >>= (uint8_t)IppTag::EndAttrs)
@@ -456,7 +453,7 @@ void IppMsg::encodeValue(Bytestream& msg, IppTag tag, const IppValue& val) const
456453
break;
457454
}
458455
default:
459-
std::cerr << "uncaught tag " << +(uint8_t)tag;
456+
ERROR(<< "uncaught tag " << +(uint8_t)tag);
460457
throw std::logic_error("Uncaught tag");
461458
}
462459
}

lib/ippprinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ void IppPrinter::_applyOverrides()
588588
Json overridesJson = Json::parse(bts.getString(bts.size()), errStr);
589589
if(!errStr.empty())
590590
{
591-
std::cerr << "Bad overrides file: " << errStr << std::endl;
591+
WARN(<< "Bad overrides file: " << errStr);
592592
}
593593
for(const auto& [matchAttrName, matchAttr] : overridesJson.object_items())
594594
{
@@ -609,6 +609,6 @@ void IppPrinter::_applyOverrides()
609609
}
610610
catch(const std::exception& e)
611611
{
612-
std::cerr << "Exception applying overrides: " << e.what() << std::endl;
612+
WARN(<< "Exception applying overrides: " << e.what());
613613
}
614614
}

lib/log.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#ifndef LOG_H
22
#define LOG_H
33

4-
#include <map>
4+
#include <iostream>
5+
#include <set>
56

67
#define LOG(category, ...) if(LogController::instance().isEnabled(category))\
78
{std::cerr __VA_ARGS__ << std::endl;}
89
#define DBG(...) LOG(LogController::Debug, __VA_ARGS__)
10+
#define WARN(...) LOG(LogController::Warning, __VA_ARGS__)
11+
#define ERROR(...) LOG(LogController::Error, __VA_ARGS__)
912

1013
class LogController
1114
{
@@ -25,26 +28,28 @@ class LogController
2528

2629
enum Category
2730
{
28-
Debug
31+
Debug,
32+
Warning,
33+
Error
2934
};
3035

3136
void enable(Category category)
3237
{
33-
_enabled[category] = true;
38+
_enabled.insert(category);
3439
}
3540

3641
void disable(Category category)
3742
{
38-
_enabled[category] = false;
43+
_enabled.erase(category);
3944
}
4045

4146
bool isEnabled(Category category)
4247
{
43-
return _enabled[category];
48+
return _enabled.find(category) != _enabled.cend();
4449
}
4550

4651
private:
47-
std::map<Category, bool> _enabled;
52+
std::set<Category> _enabled {Warning, Error};
4853

4954
};
5055

lib/ppm2pwg.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "urfpghdr.h"
88

99
#include <cstring>
10-
#include <iostream>
1110
#include <map>
1211

1312
void make_pwg_hdr(Bytestream& outBts, const PrintParameters& params, bool backside);

0 commit comments

Comments
 (0)