preamble changes started
This commit is contained in:
@ -5,36 +5,28 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
/* 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.
|
||||
* The ServiceInterfaceStream instances, which are declared below and
|
||||
* can instantaited somewhere else can be passed to these front ends by passing
|
||||
* their underlying buffers with .rdbuf() */
|
||||
namespace sif {
|
||||
extern std::ostream debug;
|
||||
extern std::ostream info;
|
||||
extern std::ostream warning;
|
||||
extern std::ostream error;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic service interface stream which can be used like std::cout or
|
||||
* std::cerr but has additional capability. Add preamble and timestamp
|
||||
* to output. Can be run in buffered or unbuffered mode.
|
||||
*/
|
||||
class ServiceInterfaceStream :
|
||||
public std::ostream {
|
||||
protected:
|
||||
ServiceInterfaceBuffer streambuf;
|
||||
ServiceInterfaceBuffer buf;
|
||||
public:
|
||||
/**
|
||||
* 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
|
||||
* @param setMessage message of preamble.
|
||||
* @param addCrToPreamble Useful for applications like Puttty.
|
||||
* @param buffered specify whether to use buffered mode.
|
||||
* @param errStream specify which output stream to use (stderr or stdout).
|
||||
*/
|
||||
ServiceInterfaceStream(std::string setMessage,
|
||||
bool errStream = false, bool addCrToPreamble = false,
|
||||
uint16_t port = 1234);
|
||||
bool addCrToPreamble = false, bool buffered = true,
|
||||
bool errStream = false, uint16_t port = 1234);
|
||||
|
||||
//! An inactive stream will not print anything.
|
||||
void setActive( bool );
|
||||
@ -45,15 +37,24 @@ public:
|
||||
* @return Preamle consisting of log message and timestamp.
|
||||
*/
|
||||
std::string getPreamble();
|
||||
|
||||
/**
|
||||
* This prints an error with a preamble. Useful if using the unbuffered
|
||||
* mode. Flushes in default mode (prints immediately).
|
||||
*/
|
||||
void print(std::string error, bool withPreamble = true,
|
||||
bool withNewline = true, bool flush = true);
|
||||
|
||||
bool buffered = false;
|
||||
};
|
||||
|
||||
// Forward declaration of interface streams. These are needed so the public
|
||||
// functions can be used by including this header
|
||||
// Forward declaration of interface streams. These should be instantiated in
|
||||
// main. They can then be used like std::cout or std::cerr.
|
||||
namespace sif {
|
||||
extern ServiceInterfaceStream debugStream;
|
||||
extern ServiceInterfaceStream infoStream;
|
||||
extern ServiceInterfaceStream warningStream;
|
||||
extern ServiceInterfaceStream errorStream;
|
||||
extern ServiceInterfaceStream debug;
|
||||
extern ServiceInterfaceStream info;
|
||||
extern ServiceInterfaceStream warning;
|
||||
extern ServiceInterfaceStream error;
|
||||
}
|
||||
|
||||
#endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ */
|
||||
|
Reference in New Issue
Block a user