diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7c45c439e2..8b541af667 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -48,6 +48,7 @@ repos: args: - --error-exitcode=1 - --language=c++ + - --inline-suppr - --force - --quiet - -j4 diff --git a/can/common.h b/can/common.h index bd1fb0ea4b..081c32e3ed 100644 --- a/can/common.h +++ b/can/common.h @@ -13,6 +13,7 @@ #include "cereal/gen/cpp/log.capnp.h" #endif +#include "opendbc/can/logger.h" #include "opendbc/can/common_dbc.h" #define INFO printf diff --git a/can/logger.h b/can/logger.h new file mode 100644 index 0000000000..bab70c4894 --- /dev/null +++ b/can/logger.h @@ -0,0 +1,27 @@ +#pragma once + +#ifdef SWAGLOG +// cppcheck-suppress preprocessorErrorDirective +#include SWAGLOG +#else + +#define CLOUDLOG_DEBUG 10 +#define CLOUDLOG_INFO 20 +#define CLOUDLOG_WARNING 30 +#define CLOUDLOG_ERROR 40 +#define CLOUDLOG_CRITICAL 50 + +#define cloudlog(lvl, fmt, ...) printf(fmt "\n", ## __VA_ARGS__) +#define cloudlog_rl(burst, millis, lvl, fmt, ...) printf(fmt "\n", ##__VA_ARGS__) + +#define LOGD(fmt, ...) cloudlog(CLOUDLOG_DEBUG, fmt, ## __VA_ARGS__) +#define LOG(fmt, ...) cloudlog(CLOUDLOG_INFO, fmt, ## __VA_ARGS__) +#define LOGW(fmt, ...) cloudlog(CLOUDLOG_WARNING, fmt, ## __VA_ARGS__) +#define LOGE(fmt, ...) cloudlog(CLOUDLOG_ERROR, fmt, ## __VA_ARGS__) + +#define LOGD_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_DEBUG, fmt, ## __VA_ARGS__) +#define LOG_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_INFO, fmt, ## __VA_ARGS__) +#define LOGW_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_WARNING, fmt, ## __VA_ARGS__) +#define LOGE_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_ERROR, fmt, ## __VA_ARGS__) + +#endif diff --git a/can/parser.cc b/can/parser.cc index d84d6b248c..92fbf37b19 100644 --- a/can/parser.cc +++ b/can/parser.cc @@ -10,7 +10,6 @@ #include #include -#include "cereal/logger/logger.h" #include "opendbc/can/common.h" int64_t get_raw_value(const std::vector &msg, const Signal &sig) { @@ -65,7 +64,7 @@ bool MessageState::parse(uint64_t nanos, const std::vector &dat) { // only update values if both checksum and counter are valid if (checksum_failed || counter_failed) { - LOGE("0x%X message checks failed, checksum failed %d, counter failed %d", address, checksum_failed, counter_failed); + LOGE_100("0x%X message checks failed, checksum failed %d, counter failed %d", address, checksum_failed, counter_failed); return false; } @@ -279,9 +278,9 @@ void CANParser::UpdateValid(uint64_t nanos) { if (state.check_threshold > 0 && (missing || timed_out)) { if (show_missing && !bus_timeout) { if (missing) { - LOGE("0x%X '%s' NOT SEEN", state.address, state.name.c_str()); + LOGE_100("0x%X '%s' NOT SEEN", state.address, state.name.c_str()); } else if (timed_out) { - LOGE("0x%X '%s' TIMED OUT", state.address, state.name.c_str()); + LOGE_100("0x%X '%s' TIMED OUT", state.address, state.name.c_str()); } } _valid = false;