/***************************************************************************** * SD Logger * ***************************************************************************** * Modified: 2010-06-01 HBr * * Modified: 2011-03-22 SMa * ****************************************************************************/ #ifndef SDLOG_H #define SDLOG_H #include #include using namespace fesa; /** @brief Logging output handler * * This class uses the UdpLogger of the FESA framework to send logging output * to a specified host and port. This can be used to receive log messages * from the FESA class on a remote computer. * * The logging message send has the following format: * 'yyyy-mm-dd hh:mm:ss:000 level FESA classname.hostname devicename {message}' * */ class SDLog { public: SDLog(); ~SDLog(); /** * Check wether logging messages are mirrored to the console. * @return true if messages are mirrored to the console */ bool isMirrorConsole() { return mirrorConsole; } /** * Enable or disable mirroring to the console * @param b true to enable and false to diable */ void setMirrorConsole(bool b) { mirrorConsole = b; } /** * Get the default FESA device instance name using this logger * @return FESA device instance name */ std::string getDefaultDevice() { return defaultDevice; } /** * Set the default FESA device instance name using this logger * @param d FESA device instance name */ void setDefaultDevice(std::string d) { defaultDevice = d; } /** * Connect to the default logging host. The host and port are defined * by the environment variables ENV_DEFAULT_HOSTNAME and ENV_DEFAULT_PORT * if defined or by the RDA properties * 'cmw.threadedLogger.logServerHostname' and * 'cmw.threadedLogger.logServerPort' if not. * @return true if successful */ bool connect(); /** * Connect to the specified host and port * @param host hostname to connect to * @param port port to connect to * @return true if successful */ bool connect(std::string host, unsigned short port); /** * Log an information message specifying additionally date, time, host name * device name and FESA class name. * Uses the default device instance name. * @param msg message */ void logInfo(std::string msg); /** * Log a warning message specifying additionally date, time, host name * device name and FESA class name * Uses the default device instance name. * @param msg message */ void logWarn(std::string msg); /** * Log an error message specifying additionally date, time, host name * device name and FESA class name * Uses the default device instance name. * @param msg message */ void logError(std::string msg); /** * Log the access to a property by a client specifying date, time, host * name, device name, FESA class name, property name and client host name * and user. * @param device FESA device instance name * @param property property name */ void logAccess(std::string device, std::string property); /** * Log an information message specifying additionally date, time, host name * device name and FESA class name * @param device FESA device instance name * @param msg message */ void logInfo(std::string device, std::string msg); /** * Log a warning message specifying additionally date, time, host name * device name and FESA class name * @param device FESA device instance name * @param msg message */ void logWarn(std::string device, std::string msg); /** * Log an error message specifying additionally date, time, host name * device name and FESA class name * @param device FESA device instance name * @param msg message */ void logError(std::string device, std::string msg); /** * Set the FESA class name to which this logging framework belongs. * @param name FESA class name */ static void setClassName(const std::string &name); /** * Get the instance of the logger object * @return reference to the logger object */ static SDLog &getInstance(); private: /** * Log a message with a specific level specifying additionally * date, time, host name device name and FESA class name. * @param device FESA device instance name * @param msg message * @param level severity level ("INFO", "WARN", "ERROR") */ void log(const std::string &device, const std::string &msg, const char *level); /** * Send the message string using the UdpLogger * @param msg message string */ void send(const char* msg); UdpLogger *udpLogger; /**< pointer to the UdpLogger */ int lastError; /**< last error code for the UdpLogger's sendStr() call */ bool mirrorConsole; /**< true, if logging should be mirrored to the console */ std::string defaultDevice; /**< default FESA device instance */ static std::string className; /**< FESA class name, to which this logger belong */ static std::string hostname; /**< name of the host on which the FESA class is running */ static SDLog *instance; /**< Instance of the logger object */ }; #endif