UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
util::syslog::SyslogMessage Class Reference

Simple wrapper around the parsing and generating os syslog messages. More...

#include "util/syslogmessage.h"

Public Member Functions

 SyslogMessage ()
 Standard constructor.
 SyslogMessage (const SyslogMessage &)=default
 Default copy constructor.
 SyslogMessage (const util::log::LogMessage &log, bool show_location)
 Constructor that converts a log message,.
virtual ~SyslogMessage ()=default
 Default destructor.
void Index (int64_t index)
 Index used to identify the message.
int64_t Index () const
 Unique index.
void Severity (SyslogSeverity severity)
SyslogSeverity Severity () const
void Facility (SyslogFacility facility)
SyslogFacility Facility () const
uint8_t Version () const
void Timestamp (uint64_t ns1970)
uint64_t Timestamp () const
void Hostname (const std::string &name)
 Sets the host name.
const std::string & Hostname () const
void ApplicationName (const std::string &name)
 Sets the application name.
const std::string & ApplicationName () const
void ProcessId (const std::string &pid)
 Sets the PID.
const std::string & ProcessId () const
void MessageId (const std::string &msg_id)
 Sets the message ID.
const std::string & MessageId () const
void Message (const std::string &msg)
 Sets the message test.
const std::string & Message () const
 Returns the message text.
void AddData (const StructuredData &data)
const std::vector< StructuredData > & DataList () const
std::string GenerateMessage () const
 Generates a syslog message.
bool ParseMessage (const std::string &msg)
 Parses a syslog message.
void AddStructuredData (const std::string &identity)
 Adds a structured data item without any parameters.
void AppendParameter (const std::string &name, const std::string &value)
void Version (uint8_t version)
void IsoTime (const std::string &iso_time)
 Sets the timestamp by converting a ISO time string.

Detailed Description

The class is a simple interface against a syslog message according to the RFC5424 standard.

Constructor & Destructor Documentation

◆ SyslogMessage() [1/2]

util::syslog::SyslogMessage::SyslogMessage ( )

Standard constructor that enables creating and parsing of system log messages.

◆ SyslogMessage() [2/2]

util::syslog::SyslogMessage::SyslogMessage ( const util::log::LogMessage & log,
bool show_location )

Constructor used when converting a log message into a syslog message, The location flag should be set if the source location should be included.

Parameters
logLog message
show_locationSet tor true if source location should be included.

Member Function Documentation

◆ AddData()

void util::syslog::SyslogMessage::AddData ( const StructuredData & data)
inline

< Adds structured data to the message.

◆ AppendParameter()

void util::syslog::SyslogMessage::AppendParameter ( const std::string & name,
const std::string & value )

Append parameter item to the last data item.

◆ ApplicationName()

const std::string & util::syslog::SyslogMessage::ApplicationName ( ) const
inlinenodiscard

< Returns the application name

◆ DataList()

const std::vector< StructuredData > & util::syslog::SyslogMessage::DataList ( ) const
inlinenodiscard

< Returns a list of structured data items.

◆ Facility() [1/2]

SyslogFacility util::syslog::SyslogMessage::Facility ( ) const
inlinenodiscard

< Returns the facility code.

◆ Facility() [2/2]

void util::syslog::SyslogMessage::Facility ( SyslogFacility facility)
inline

< Sets the facility code

◆ Hostname()

const std::string & util::syslog::SyslogMessage::Hostname ( ) const
inlinenodiscard

< Returns the host name

◆ Index()

void util::syslog::SyslogMessage::Index ( int64_t index)
inline

Index that is used as an unique identifier of the message. The index is not received or transmitted.

Parameters
index64-bit unique index. Optional use.

◆ IsoTime()

void util::syslog::SyslogMessage::IsoTime ( const std::string & iso_time)

Function that is used when parsing syslog messages and converts the incoming ISO time string into a timestamp.

Parameters
iso_timeISO time formatted string.

◆ Message() [1/2]

const std::string & util::syslog::SyslogMessage::Message ( ) const
inlinenodiscard

Returns the message text. Note that the string is UTF8 decoded.

Returns
Messag text.

◆ Message() [2/2]

void util::syslog::SyslogMessage::Message ( const std::string & msg)

Sets the message text. Note that it assume that the string is UTF8 decoded.

Parameters
msgUTF8 decoded string.

◆ MessageId()

const std::string & util::syslog::SyslogMessage::MessageId ( ) const
inlinenodiscard

< Returns the message ID

◆ ProcessId()

const std::string & util::syslog::SyslogMessage::ProcessId ( ) const
inlinenodiscard

< Returns the PID

◆ Severity() [1/2]

SyslogSeverity util::syslog::SyslogMessage::Severity ( ) const
inlinenodiscard

< Returns the severity level

◆ Severity() [2/2]

void util::syslog::SyslogMessage::Severity ( SyslogSeverity severity)
inline

< Sets the severity level

◆ Timestamp() [1/2]

uint64_t util::syslog::SyslogMessage::Timestamp ( ) const
inlinenodiscard

< Returns the timestamp (ns since 1970).

◆ Timestamp() [2/2]

void util::syslog::SyslogMessage::Timestamp ( uint64_t ns1970)
inline

< Sets the timestamp (ns since 1970).

◆ Version() [1/2]

uint8_t util::syslog::SyslogMessage::Version ( ) const
inlinenodiscard

< Returns the version.

◆ Version() [2/2]

void util::syslog::SyslogMessage::Version ( uint8_t version)
inline

< Sets the version number. Default is 1.


The documentation for this class was generated from the following file: