/* * File: Log.h * Author: lpiccoli * * Created on September 28, 2010, 2:31 PM */ #ifndef _LOG_H #define _LOG_H #include "Defs.h" #include "PvData.h" #include #include FF_NAMESPACE_START /** * This class is a wrapper for the errlogPrintfNoConsole(). * * It automatically prepends tags for the loop name (fac tag) and slot name * (process tag) to the message string. * * There is one static object Log that can be used for messages not * related to a feedback loop. * * This class is *not* thread safe! * * @author L.Piccoli */ class Log { public: /** * Possible Log operations. These must be added at the end of a sequence * of << operators: * o cout: output using std::cout * o flush: message is sent to Log only * o flushpv: message is written to the STATUSSTR PV besides going to the Log * o flushpvonly: message is written to STATUSSTR PV only * o clearpv: erase status message in STATUSSTR PV */ enum LogOperatorType { cout, flush, flushpv, flushpvnoalarm, flushpvonly, flushpvonlynoalarm, clearpv, }; Log(std::string loopName = "Fbck", std::string slotName = "Fbck"); Log &operator<<(char const *message); Log &operator<<(int const value); Log &operator<<(long int const value); Log &operator<<(double const value); Log &operator<<(LogOperatorType const operation); void flushMessage(); void clear(); void logToConsole(bool log = true); void setLoopName(std::string loopName); void setSlotName(std::string slotName); void setAllLogToConsole(bool log = true); void setStatusstrPv(PvDataCharWaveform *pvCharWaveform); static Log &getInstance(); private: void setStatusStrPv(bool alarm = true); void clearStatusPv(); /** The message */ std::ostringstream _message; /** Header sent to the logger */ std::string _messageHeader; /** Loop name */ std::string _loopName; /** Slot name */ std::string _slotName; /** * Defines whether messages are logged only or are printed out to the * console */ bool _logToConsole; /** * Pointer to the STATUSSTR PV if this Log instance is used for a particular * feedback loop. */ // PvDataString *_statusStrPv; PvDataCharWaveform *_statusStrPv; /** * Static variable that defines if *all* logs should print out to * the console. */ static bool _allLogToConsole; /** System wide Log instance */ static Log _instance; }; FF_NAMESPACE_END #endif