Commit fda8f6a5 authored by Stefan Hackenberg's avatar Stefan Hackenberg
Browse files

Initial commit

parents
{
"authors": {
"name": "Stefan Hackenberg"
},
"description": "Logger library forked from https://os.mbed.com/users/ollie8/code/Logger/",
"frameworks": "mbed",
"keywords": [],
"name": "mbed-logger",
"platforms": "*",
"repository": {
"type": "git",
"url": "https://gitlab.elektrotechnik.hs-augsburg.de/hackenbs/mbed-logger.git"
}
}
#ifndef LOGGER_H
#define LOGGER_H
#include "mbed.h"
// Cascade defined
#if defined(LOG_LEVEL_TRACE) && !defined(LOG_LEVEL_DEBUG)
#define LOG_LEVEL_DEBUG
#endif
#if defined(LOG_LEVEL_DEBUG) && !defined(LOG_LEVEL_INFO)
#define LOG_LEVEL_INFO
#endif
#if defined(LOG_LEVEL_INFO) && !defined(LOG_LEVEL_WARN)
#define LOG_LEVEL_WARN
#endif
#if defined(LOG_LEVEL_WARN) && !defined(LOG_LEVEL_ERROR)
#define LOG_LEVEL_ERROR
#endif
// Genuine definitions
#if defined(LOG_LEVEL_TRACE)
#define TRACE(x, ...) std::printf("[TRACE: %s:%d] " x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#else
#define TRACE(x, ...)
#endif
#if defined(LOG_LEVEL_DEBUG)
#define DEBUG(x, ...) std::printf("[DEBUG: %s:%d] " x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define DEBUGARRAY(buffer, length, x, ...) \
std::printf("[DEBUG: %s:%d] " x " ", __FILE__, __LINE__, ##__VA_ARGS__); \
printfhex(buffer, length)
#else
#define DEBUG(x, ...)
#define DEBUGARRAY(buffer, length, x, ...)
#endif
#if defined(LOG_LEVEL_INFO)
#define INFO(x, ...) std::printf("[INFO: %s:%d] " x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#else
#define INFO(x, ...)
#endif
#if defined(LOG_LEVEL_WARN)
#define WARN(x, ...) std::printf("[WARN: %s:%d] " x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#else
#define WARN(x, ...)
#endif
#if defined(LOG_LEVEL_ERROR)
#define ERROR(x, ...) std::printf("[ERROR: %s:%d] " x "\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#else
#define ERROR(x, ...)
#endif
static inline void printfhex(const uint8_t *buffer, size_t length)
{
for (size_t i = 0; i < length; i++)
{
printf("%02x ", buffer[i]);
}
printf("\r\n");
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment