stumpless 2.2.0
Loading...
Searching...
No Matches
stumpless::SocketTarget Class Reference

Socket targets allow logs to be sent to a Unix domain socket, like the frequently used /dev/log or /var/run/syslog sockets associated with syslog daemons. More...

#include <SocketTarget.hpp>

Public Member Functions

 SocketTarget (struct stumpless_target *equivalent)
 
 SocketTarget (const char *name, const char *local_socket)
 Opens a socket target.
 
 ~SocketTarget (void)
 Closes this target and releases all memory and other resources held by it.
 
const char * GetDefaultAppName (void)
 Returns the default app name used by this target.
 
const char * GetDefaultMsgid (void)
 Returns the default msgid used by this target.
 
Facility GetDefaultFacility (void)
 Gets the default facility of this target.
 
stumpless_filter_func_t GetFilter (void)
 Returns the current filter used by this target to determine if entries should be allowed through it.
 
int GetMask (void)
 Gets the log mask of this target.
 
const char * GetName (void)
 Returns the name of this target.
 
int GetOption (int option)
 Gets the given option for this target.
 
bool IsOpen (void)
 Checks to see if this target is open.
 
SocketTargetLog (const char *message,...)
 Writes a string message to this target.
 
SocketTargetLog (int priority, const char *message,...)
 Writes a log message with the given priority to this target.
 
SocketTargetLog (Facility facility, Severity severity, const char *message,...)
 Writes a log message with the given facility and severity to this target.
 
SocketTargetLog (Entry entry)
 Writes an Entry to this target.
 
void Open (void)
 Opens this target if it has been paused.
 
SocketTargetSetDefaultAppName (const char *app_name)
 Sets the default app name for this target.
 
SocketTargetSetDefaultFacility (int facility)
 Sets the default facility of the target.
 
SocketTargetSetDefaultMsgid (const char *msgid)
 Sets the default message id for this target.
 
SocketTargetSetFilter (stumpless_filter_func_t filter)
 Sets the filter used by this target to determine whether entries should be logged to it.
 
SocketTargetSetMask (int mask)
 Sets the log mask of a target.
 
SocketTargetSetOption (int option)
 Sets an option on a target.
 
SocketTargetUnsetOption (int option)
 Unsets an option on a target.
 

Public Attributes

struct stumpless_target * equivalent
 

Static Public Attributes

static const char * DEFAULT_SOCKET
 A string literal with the default socket logged to.
 

Detailed Description

Socket targets allow logs to be sent to a Unix domain socket, like the frequently used /dev/log or /var/run/syslog sockets associated with syslog daemons.

Constructor & Destructor Documentation

◆ SocketTarget() [1/2]

stumpless::SocketTarget::SocketTarget ( struct stumpless_target * equivalent)

◆ SocketTarget() [2/2]

stumpless::SocketTarget::SocketTarget ( const char * name,
const char * local_socket )

Opens a socket target.

Parameters
nameThe name of the socket to send logs to.
local_socketThe name of the Unix domain socket to connect from. This can be set to NULL if you'd like to simply let the target generate one.

◆ ~SocketTarget()

stumpless::SocketTarget::~SocketTarget ( void )

Closes this target and releases all memory and other resources held by it.

Notably, the connection to the socket is closed, and the local socket is cleaned up.

Member Function Documentation

◆ GetDefaultAppName()

const char * stumpless::SocketTarget::GetDefaultAppName ( void )

Returns the default app name used by this target.

The returned character buffer must be freed by the caller when it is no longer needed to avoid memory leaks. Available since release v2.0.0.

Returns
The default app name of this target.

◆ GetDefaultFacility()

Facility stumpless::SocketTarget::GetDefaultFacility ( void )

Gets the default facility of this target.

Returns
The default facility of this target.

◆ GetDefaultMsgid()

const char * stumpless::SocketTarget::GetDefaultMsgid ( void )

Returns the default msgid used by this target.

The returned character buffer must be freed by the caller when it is no longer needed to avoid memory leaks. Available since release v2.0.0.

Returns
The default msgid of this target.

◆ GetFilter()

stumpless_filter_func_t stumpless::SocketTarget::GetFilter ( void )

Returns the current filter used by this target to determine if entries should be allowed through it.

Note that NULL is a valid return value from this function, indicating that the target does not currently have a filter set. Available since release v2.1.0.

Returns
The filter function in use by this target.

◆ GetMask()

int stumpless::SocketTarget::GetMask ( void )

Gets the log mask of this target.

The mask is a bit field of severities that this target will allow if the default mask-based filter is in use. These can be formed and checked using the STUMPLESS_SEVERITY_MASK and STUMPLESS_SEVERITY_MASK_UPTO macros, and combining them using bitwise or operations. Available since release v2.1.0.

Returns
The current mask of this target.

◆ GetName()

const char * stumpless::SocketTarget::GetName ( void )

Returns the name of this target.

The returned character buffer must be freed by the caller when it is no longer needed to avoid memory leaks. Available since release v2.0.0.

Returns
The name of this Target.

◆ GetOption()

int stumpless::SocketTarget::GetOption ( int option)

Gets the given option for this target.

While the returned value is the option if it is set, callers can also simply use the truth value of the return to see if the provided option is set.

Parameters
optionThe option to check this target for.
Returns
The option if it is set on the target. If the option is not set, then zero is returned.

◆ IsOpen()

bool stumpless::SocketTarget::IsOpen ( void )

Checks to see if this target is open.

Returns
True if the target is open, false otherwise.

◆ Log() [1/4]

SocketTarget & stumpless::SocketTarget::Log ( const char * message,
... )

Writes a string message to this target.

Parameters
messageThe message to log, optionally containing any format specifiers valid in printf. This may be NULL, in which case an event with no message is logged.
...Substitutions for any format specifiers provided in message. The number of substitutions provided must exactly match the number of specifiers given.
Returns
The modified target.

◆ Log() [2/4]

SocketTarget & stumpless::SocketTarget::Log ( Entry entry)

Writes an Entry to this target.

Parameters
entrythe entry to write
Returns
The modified target.

◆ Log() [3/4]

SocketTarget & stumpless::SocketTarget::Log ( Facility facility,
Severity severity,
const char * message,
... )

Writes a log message with the given facility and severity to this target.

Parameters
facilityThe facility code of the message.
severityThe severity code of the message.
messageThe message to log, optionally containing any format specifiers valid in printf.
...Substitutions for any format specifiers provided in message. The number of substitutions provided must exactly match the number of specifiers given.
Returns
The modified target.

◆ Log() [4/4]

SocketTarget & stumpless::SocketTarget::Log ( int priority,
const char * message,
... )

Writes a log message with the given priority to this target.

Parameters
priorityThe priority of the message, described in RFC 5424 as the PRIVAL. This should be the bitwise or of the integer values of a Facility and a Severity.
messageThe message to log, optionally containing any format specifiers valid in printf.
...Substitutions for any format specifiers provided in message. The number of substitutions provided must exactly match the number of specifiers given.
Returns
The modified target.

◆ Open()

void stumpless::SocketTarget::Open ( void )

Opens this target if it has been paused.

◆ SetDefaultAppName()

SocketTarget & stumpless::SocketTarget::SetDefaultAppName ( const char * app_name)

Sets the default app name for this target.

Parameters
app_nameThe new default app name, as a NULL-terminated string.
Returns
The modified target.

◆ SetDefaultFacility()

SocketTarget & stumpless::SocketTarget::SetDefaultFacility ( int facility)

Sets the default facility of the target.

Parameters
facilityThe default facility for the target to use. This should be a STUMPLESS_FACILITY value.
Returns
The modified target.

◆ SetDefaultMsgid()

SocketTarget & stumpless::SocketTarget::SetDefaultMsgid ( const char * msgid)

Sets the default message id for this target.

Parameters
msgidThe new default message id, as a NULL-terminated string.
Returns
The modified target.

◆ SetFilter()

SocketTarget & stumpless::SocketTarget::SetFilter ( stumpless_filter_func_t filter)

Sets the filter used by this target to determine whether entries should be logged to it.

Available since release v2.1.0.

Parameters
filterThe new filter to use for this target.
Returns
The modified target.

◆ SetMask()

SocketTarget & stumpless::SocketTarget::SetMask ( int mask)

Sets the log mask of a target.

The mask is a bit field of severities that this target will allow if the default mask-based filter is in use. These can be formed and checked using the STUMPLESS_SEVERITY_MASK and STUMPLESS_SEVERITY_MASK_UPTO macros, and combining them using bitwise or operations. Available since release v2.1.0.

Parameters
maskThe new mask to use for this target.
Returns
The modified target.

◆ SetOption()

SocketTarget & stumpless::SocketTarget::SetOption ( int option)

Sets an option on a target.

Parameters
optionThe option to set. This should be a STUMPLESS_OPTION value.
Returns
The modified target.

◆ UnsetOption()

SocketTarget & stumpless::SocketTarget::UnsetOption ( int option)

Unsets an option on a target.

Parameters
optionThe option to unset. This should be a STUMPLESS_OPTION value.
Returns
The modified target.

Member Data Documentation

◆ DEFAULT_SOCKET

const char* stumpless::SocketTarget::DEFAULT_SOCKET
static

A string literal with the default socket logged to.

◆ equivalent

struct stumpless_target* stumpless::SocketTarget::equivalent

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