Skip to content

Commit

Permalink
simplify log facility handling
Browse files Browse the repository at this point in the history
  • Loading branch information
john30 committed Feb 24, 2024
1 parent 3d62365 commit d6ea68d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ebusd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int main(int argc, char* argv[], char* envp[]) {
}

if (s_opt.logAreas != -1 || s_opt.logLevel != ll_COUNT) {
setFacilitiesLogLevel(LF_ALL, ll_none);
setFacilitiesLogLevel(1<<ll_COUNT, ll_none);
setFacilitiesLogLevel(s_opt.logAreas, s_opt.logLevel);
}

Expand Down
8 changes: 2 additions & 6 deletions src/lib/utils/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ int parseLogFacilities(const char* facilities) {
free(input);
return -1;
}
if (val == lf_COUNT) {
newFacilites = LF_ALL;
} else {
newFacilites |= 1 << val;
}
newFacilites |= 1 << val;
}
free(input);
return newFacilites;
Expand Down Expand Up @@ -139,7 +135,7 @@ const char* getLogLevelStr(LogLevel level) {
bool setFacilitiesLogLevel(int facilities, LogLevel level) {
bool changed = false;
for (int val = 0; val < lf_COUNT && facilities != 0; val++) {
if ((facilities & (1 << val)) != 0 && s_facilityLogLevel[(LogFacility)val] != level) {
if ((facilities & ((1 << val)|(1 << lf_COUNT))) != 0 && s_facilityLogLevel[(LogFacility)val] != level) {
s_facilityLogLevel[(LogFacility)val] = level;
changed = true;
}
Expand Down
5 changes: 1 addition & 4 deletions src/lib/utils/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ enum LogFacility {
lf_bus, //!< eBUS related
lf_update, //!< updates found while listening to the bus
lf_other, //!< all other log facilities
lf_COUNT = 5 //!< number of available log facilities
lf_COUNT = 5 //!< number of available log facilities and flag for setting all
};

/** macro for all log facilities. */
#define LF_ALL ((1 << lf_main) | (1 << lf_network) | (1 << lf_bus) | (1 << lf_update) | (1 << lf_other))

/** the available log levels. */
enum LogLevel {
ll_none = 0, //!< no level at all
Expand Down

0 comments on commit d6ea68d

Please sign in to comment.