more improvements:
1. New optional flag to redirect print to stderr. THis can be useful on host environemtns (e.g linux) 2. non-buffered mode if this flag is true: the preamble msut be printed manually 2. Getter function for preamble for that case. 3. printChar function: specify whether to print to stderr or stdout
This commit is contained in:
@ -3,11 +3,9 @@
|
||||
|
||||
#include <framework/serviceinterface/ServiceInterfaceBuffer.h>
|
||||
#include <iostream>
|
||||
#include <iosfwd>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
|
||||
// Unfortunately, there must be a forward declaration of log_fe
|
||||
// Unfortunately, there must be a forward declaration of the log front end
|
||||
// (MUST be defined in main), to let the system know where to write to.
|
||||
namespace sif {
|
||||
extern std::ostream debug;
|
||||
@ -18,14 +16,41 @@ extern std::ostream error;
|
||||
|
||||
|
||||
class ServiceInterfaceStream :
|
||||
public std::basic_ostream<char, std::char_traits<char>> {
|
||||
public std::ostream {
|
||||
protected:
|
||||
ServiceInterfaceBuffer buf;
|
||||
public:
|
||||
ServiceInterfaceStream( std::string set_message,
|
||||
bool addCrToPreamble = false, uint16_t port = 1234);
|
||||
/**
|
||||
* This constructor is used by specifying the preamble message.
|
||||
* Optionally, the output can be directed to stderr and a CR character
|
||||
* can be prepended to the preamble.
|
||||
* @param set_message
|
||||
* @param errStream
|
||||
* @param addCrToPreamble
|
||||
* @param port
|
||||
*/
|
||||
ServiceInterfaceStream(std::string setMessage,
|
||||
bool errStream = false, bool addCrToPreamble = false,
|
||||
uint16_t port = 1234);
|
||||
|
||||
//! An inactive stream will not print anything.
|
||||
void setActive( bool );
|
||||
|
||||
/**
|
||||
* This can be used to retrieve the preamble in case it should be printed in
|
||||
* the unbuffered mode.
|
||||
* @return Preamle consisting of log message and timestamp.
|
||||
*/
|
||||
std::string getPreamble();
|
||||
};
|
||||
|
||||
// Forward declaration of interface streams. These are needed so the public
|
||||
// functions can be used by including this header
|
||||
namespace sif {
|
||||
extern ServiceInterfaceStream debugStream;
|
||||
extern ServiceInterfaceStream infoStream;
|
||||
extern ServiceInterfaceStream warningStream;
|
||||
extern ServiceInterfaceStream errorStream;
|
||||
}
|
||||
|
||||
#endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ */
|
||||
|
Reference in New Issue
Block a user