Ollie Milton / Logger

logger.h

Committer:
ollie8
Date:
2015-08-18
Revision:
0:46f37f02c1f1
Child:
1:2e4615f18293

File content as of revision 0:46f37f02c1f1:

#ifndef __LOGGER_H__
#define __LOGGER_H__

#include "mbed.h"

#if defined LOG_TRACE
#define TRACE(x, ...) std::printf("[TRACE: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define DEBUG(x, ...) std::printf("[DEBUG: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);

#elif defined LOG_DEBUG
#define TRACE(x, ...)
#define DEBUG(x, ...) std::printf("[DEBUG: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);

#elif defined LOG_INFO
#define TRACE(x, ...)
#define DEBUG(x, ...)
#define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);

#elif defined LOG_WARN
#define TRACE(x, ...)
#define DEBUG(x, ...)
#define INFO(x, ...)
#define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);
#define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);

#elif defined LOG_ERROR
#define TRACE(x, ...)
#define DEBUG(x, ...)
#define INFO(x, ...)
#define WARN(x, ...)
#define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__);

#else
#define TRACE(x, ...)
#define DEBUG(x, ...)
#define INFO(x, ...)
#define WARN(x, ...)
#define ERROR(x, ...)
#endif

class SerialLogger {

    private: 
        Serial *pc;
    
    public:
        SerialLogger() {
            pc = new Serial(USBTX, USBRX);    
        }
        
        void start() {
            pc->baud(460800);
        }
};


#endif