Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
logger.h@1:2e4615f18293, 2015-08-18 (annotated)
- Committer:
- ollie8
- Date:
- Tue Aug 18 11:48:16 2015 +0000
- Revision:
- 1:2e4615f18293
- Parent:
- 0:46f37f02c1f1
- Child:
- 2:aa7033f339e1
Baud rate can now be passed into start method
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ollie8 | 0:46f37f02c1f1 | 1 | #ifndef __LOGGER_H__ |
| ollie8 | 0:46f37f02c1f1 | 2 | #define __LOGGER_H__ |
| ollie8 | 0:46f37f02c1f1 | 3 | |
| ollie8 | 0:46f37f02c1f1 | 4 | #include "mbed.h" |
| ollie8 | 0:46f37f02c1f1 | 5 | |
| ollie8 | 0:46f37f02c1f1 | 6 | #if defined LOG_TRACE |
| ollie8 | 0:46f37f02c1f1 | 7 | #define TRACE(x, ...) std::printf("[TRACE: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 8 | #define DEBUG(x, ...) std::printf("[DEBUG: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 9 | #define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 10 | #define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 11 | #define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 12 | |
| ollie8 | 0:46f37f02c1f1 | 13 | #elif defined LOG_DEBUG |
| ollie8 | 0:46f37f02c1f1 | 14 | #define TRACE(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 15 | #define DEBUG(x, ...) std::printf("[DEBUG: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 16 | #define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 17 | #define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 18 | #define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 19 | |
| ollie8 | 0:46f37f02c1f1 | 20 | #elif defined LOG_INFO |
| ollie8 | 0:46f37f02c1f1 | 21 | #define TRACE(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 22 | #define DEBUG(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 23 | #define INFO(x, ...) std::printf("[INFO: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 24 | #define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 25 | #define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 26 | |
| ollie8 | 0:46f37f02c1f1 | 27 | #elif defined LOG_WARN |
| ollie8 | 0:46f37f02c1f1 | 28 | #define TRACE(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 29 | #define DEBUG(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 30 | #define INFO(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 31 | #define WARN(x, ...) std::printf("[WARN: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 32 | #define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 33 | |
| ollie8 | 0:46f37f02c1f1 | 34 | #elif defined LOG_ERROR |
| ollie8 | 0:46f37f02c1f1 | 35 | #define TRACE(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 36 | #define DEBUG(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 37 | #define INFO(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 38 | #define WARN(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 39 | #define ERROR(x, ...) std::printf("[ERROR: %s:%d]"x"\r\n", __FILE__, __LINE__, ##__VA_ARGS__); |
| ollie8 | 0:46f37f02c1f1 | 40 | |
| ollie8 | 0:46f37f02c1f1 | 41 | #else |
| ollie8 | 0:46f37f02c1f1 | 42 | #define TRACE(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 43 | #define DEBUG(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 44 | #define INFO(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 45 | #define WARN(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 46 | #define ERROR(x, ...) |
| ollie8 | 0:46f37f02c1f1 | 47 | #endif |
| ollie8 | 0:46f37f02c1f1 | 48 | |
| ollie8 | 0:46f37f02c1f1 | 49 | class SerialLogger { |
| ollie8 | 0:46f37f02c1f1 | 50 | |
| ollie8 | 0:46f37f02c1f1 | 51 | private: |
| ollie8 | 0:46f37f02c1f1 | 52 | Serial *pc; |
| ollie8 | 0:46f37f02c1f1 | 53 | |
| ollie8 | 0:46f37f02c1f1 | 54 | public: |
| ollie8 | 0:46f37f02c1f1 | 55 | SerialLogger() { |
| ollie8 | 0:46f37f02c1f1 | 56 | pc = new Serial(USBTX, USBRX); |
| ollie8 | 0:46f37f02c1f1 | 57 | } |
| ollie8 | 0:46f37f02c1f1 | 58 | |
| ollie8 | 1:2e4615f18293 | 59 | void start(int baudRate = 460800) { |
| ollie8 | 1:2e4615f18293 | 60 | pc->baud(baudRate); |
| ollie8 | 0:46f37f02c1f1 | 61 | } |
| ollie8 | 0:46f37f02c1f1 | 62 | }; |
| ollie8 | 0:46f37f02c1f1 | 63 | |
| ollie8 | 0:46f37f02c1f1 | 64 | |
| ollie8 | 0:46f37f02c1f1 | 65 | #endif |