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.
Fork of LogUtil by
LogUtil.h
00001 /** 00002 * @file LogUtil.h 00003 * @brief Utility to log messages during runtime 00004 * @author sam grove 00005 * @version 1.0 00006 * @see http://www.drdobbs.com/cpp/a-lightweight-logger-for-c/240147505 00007 * 00008 * Copyright (c) 2013 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 #ifndef LOGUTIL_H 00024 #define LOGUTIL_H 00025 00026 #include <stdio.h> 00027 #include <stdlib.h> 00028 #include "mbed.h" 00029 00030 #define STREAM stdout 00031 #define LOG(...) \ 00032 fprintf(STREAM, "LOG: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 00033 fprintf(STREAM, ##__VA_ARGS__); \ 00034 fflush(STREAM) 00035 #define WARN(...) \ 00036 fprintf(STREAM, "WARN: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 00037 fprintf(STREAM, ##__VA_ARGS__); \ 00038 fflush(STREAM) 00039 #define ERROR(...) \ 00040 fprintf(STREAM, "ERROR: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \ 00041 fprintf(STREAM, ##__VA_ARGS__); \ 00042 fflush(STREAM); \ 00043 exit(1) 00044 00045 /** Using the LogUtil class 00046 * 00047 * Example: 00048 * @code 00049 * #include "mbed.h" 00050 * #include "LogUtil.h" 00051 * 00052 * LogUtil logger; 00053 * 00054 * int main() 00055 * { 00056 * LOG("This is a log\n"); 00057 * WARN("This is a warning\n"); 00058 * 00059 * for(int i=0; i<3; ++i) { 00060 * LOG("Log message #%d\n", i); 00061 * } 00062 * 00063 * for(int i=0; i<3; ++i) { 00064 * WARN("Warn message #%d\n", i); 00065 * } 00066 * 00067 * ERROR("This is an error\n"); 00068 * } 00069 * @endcode 00070 */ 00071 00072 /** 00073 * @class LogUtil 00074 * @brief Different ways to log messages having a standard interface 00075 */ 00076 class LogUtil 00077 { 00078 private: 00079 Serial *_serial; 00080 public: 00081 00082 /** Construct the LogUtil class and configure 00083 */ 00084 LogUtil(Serial &serial, uint32_t baudrate = 0); 00085 00086 }; 00087 00088 00089 #endif 00090 00091
Generated on Sat Jul 23 2022 11:00:12 by
1.7.2
