#ifndef LOGGING_H #define LOGGING_H #include #include #if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif //#include "pins_arduino.h" extern "C" { #include } #define LOG_LEVEL_NOOUTPUT 0 #define LOG_LEVEL_ERRORS 1 #define LOG_LEVEL_INFOS 2 #define LOG_LEVEL_DEBUG 3 #define LOG_LEVEL_VERBOSE 4 // default loglevel if nothing is set from user #define LOGLEVEL LOG_LEVEL_DEBUG #define CR "\r\n" #define LOGGING_VERSION 1 /*! * Logging is a helper class to output informations over * RS232. If you know log4j or log4net, this logging class * is more or less similar ;-)
* Different loglevels can be used to extend or reduce output * All methods are able to handle any number of output parameters. * All methods print out a formated string (like printf).
* To reduce output and program size, reduce loglevel. *
* Output format string can contain below wildcards. Every wildcard * must be start with percent sign (\%) * * Depending on loglevel, source code is excluded from compile !
*
* Wildcards
*
    *
  • \%s replace with an string (char*)
  • *
  • \%c replace with an character
  • *
  • \%d replace with an integer value
  • *
  • \%l replace with an long value
  • *
  • \%x replace and convert integer value into hex
  • *
  • \%X like %x but combine with 0x123AB
  • *
  • \%b replace and convert integer value into binary
  • *
  • \%B like %x but combine with 0b10100011
  • *
  • \%t replace and convert boolean value into "t" or "f"
  • *
  • \%T like %t but convert into "true" or "false"
  • *

* Loglevels
* * * * * * *
0LOG_LEVEL_NOOUTPUTno output
1LOG_LEVEL_ERRORSonly errors
2LOG_LEVEL_INFOSerrors and info
3LOG_LEVEL_DEBUGerrors, info and debug
4LOG_LEVEL_VERBOSEall
*
*

History


* * * * */ class Logging { private: int _level; long _baud; public: /*! * default Constructor */ Logging(){} ; /** * Initializing, must be called as first. * \param void * \return void * */ void Init(int level, long baud); /** * Output an error message. Output message contains * ERROR: followed by original msg * Error messages are printed out, at every loglevel * except 0 ;-) * \param msg format string to output * \param ... any number of variables * \return void */ void Error(char* msg, ...); /** * Output an info message. Output message contains * Info messages are printed out at l * loglevels >= LOG_LEVEL_INFOS * * \param msg format string to output * \param ... any number of variables * \return void */ void Info(char* msg, ...); /** * Output an debug message. Output message contains * Debug messages are printed out at l * loglevels >= LOG_LEVEL_DEBUG * * \param msg format string to output * \param ... any number of variables * \return void */ void Debug(char* msg, ...); /** * Output an verbose message. Output message contains * Debug messages are printed out at l * loglevels >= LOG_LEVEL_VERBOSE * * \param msg format string to output * \param ... any number of variables * \return void */ void Verbose(char* msg, ...); private: void print(const char *format, va_list args); }; extern Logging Log; #endif
01 FEB 2012initial release
06 MAR 2012implement a preinstanciate object (like in Wire, ...)
methode init get now loglevel and baud parameter