class Poco::Message
Overview
This class represents a log message that is sent through a chain of log channels. More…
#include <Message.h> class Message { public: // enums enum Priority; // construction Message(); Message( const std::string& source, const std::string& text, Priority prio ); Message( const std::string& source, const std::string& text, Priority prio, const char* file, int line ); Message(const Message& msg); Message( const Message& msg, const std::string& text ); // methods Message& operator=(const Message& msg); void swap(Message& msg); void setSource(const std::string& src); const std::string& getSource() const; void setText(const std::string& text); const std::string& getText() const; void setPriority(Priority prio); Priority getPriority() const; void setTime(const Timestamp& time); const Timestamp& getTime() const; void setThread(const std::string& thread); const std::string& getThread() const; void setTid(long pid); long getTid() const; void setPid(long pid); long getPid() const; void setSourceFile(const char* file); const char* getSourceFile() const; void setSourceLine(int line); int getSourceLine() const; bool has(const std::string& param) const; const std::string& get(const std::string& param) const; const std::string& get( const std::string& param, const std::string& defaultValue ) const; void set( const std::string& param, const std::string& value ); const std::string& operator[](const std::string& param) const; std::string& operator[](const std::string& param); protected: // typedefs typedef std::map<std::string, std::string> StringMap; // methods void init(); };
Detailed Documentation
This class represents a log message that is sent through a chain of log channels.
A Message contains a priority denoting the severity of the message, a source describing its origin, a text describing its meaning, the time of its creation, and an identifier of the process and thread that created the message.
Optionally a Message can also contain the source file path and line number of the statement generating the message.
A Message can also contain any number of named parameters that contain additional information about the event that caused the message.
Construction
Message()
Creates an empty Message.
The thread and process ids are set.
Message( const std::string& source, const std::string& text, Priority prio )
Creates a Message with the given source, text and priority.
The thread and process ids are set.
Message( const std::string& source, const std::string& text, Priority prio, const char* file, int line )
Creates a Message with the given source, text, priority, source file path and line.
The source file path must be a static string with a lifetime that’s at least the lifetime of the message object (the string is not copied internally). Usually, this will be the path string obtained from the FILE macro.
The thread and process ids are set.
Message(const Message& msg)
Creates a Message by copying another one.
Message( const Message& msg, const std::string& text )
Creates a Message by copying all but the text from another message.
Methods
Message& operator=(const Message& msg)
Assignment operator.
void swap(Message& msg)
Swaps the message with another one.
void setSource(const std::string& src)
Sets the source of the message.
const std::string& getSource() const
Returns the source of the message.
void setText(const std::string& text)
Sets the text of the message.
const std::string& getText() const
Returns the text of the message.
void setPriority(Priority prio)
Sets the priority of the message.
Priority getPriority() const
Returns the priority of the message.
void setTime(const Timestamp& time)
Sets the time of the message.
const Timestamp& getTime() const
Returns the time of the message.
void setThread(const std::string& thread)
Sets the thread identifier for the message.
const std::string& getThread() const
Returns the thread identifier for the message.
void setTid(long pid)
Sets the numeric thread identifier for the message.
long getTid() const
Returns the numeric thread identifier for the message.
void setPid(long pid)
Sets the process identifier for the message.
long getPid() const
Returns the process identifier for the message.
void setSourceFile(const char* file)
Sets the source file path of the statement generating the log message.
File must be a static string, such as the value of the FILE macro. The string is not copied internally for performance reasons.
const char* getSourceFile() const
Returns the source file path of the code creating the message.
May be 0 if not set.
void setSourceLine(int line)
Sets the source file line of the statement generating the log message.
This is usually the result of the LINE macro.
int getSourceLine() const
Returns the source file line of the statement generating the log message.
May be 0 if not set.
bool has(const std::string& param) const
Returns true if a parameter with the given name exists.
const std::string& get(const std::string& param) const
Returns a const reference to the value of the parameter with the given name.
Throws a NotFoundException if the parameter does not exist.
const std::string& get( const std::string& param, const std::string& defaultValue ) const
Returns a const reference to the value of the parameter with the given name.
If the parameter with the given name does not exist, then defaultValue is returned.
void set( const std::string& param, const std::string& value )
Sets the value for a parameter.
If the parameter does not exist, then it is created.
const std::string& operator[](const std::string& param) const
Returns a const reference to the value of the parameter with the given name.
Throws a NotFoundException if the parameter does not exist.
std::string& operator[](const std::string& param)
Returns a reference to the value of the parameter with the given name.
This can be used to set the parameter’s value. If the parameter does not exist, it is created with an empty string value.