A target that will write log messages to a provided buffer, wrapping around when the end is reached.
More...
#include <BufferTarget.hpp>
|
| BufferTarget (struct stumpless_target *equivalent) |
|
| BufferTarget (const char *name, char *buffer, size_t size) |
| Opens a buffer target for the given buffer.
|
|
| ~BufferTarget (void) |
| Closes the target and releases all memory owned by it.
|
|
size_t | Read (char *buffer, size_t max_length) |
| Reads the next message from this target and writes it into the given buffer.
|
|
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.
|
|
BufferTarget & | Log (const char *message,...) |
| Writes a string message to this target.
|
|
BufferTarget & | Log (int priority, const char *message,...) |
| Writes a log message with the given priority to this target.
|
|
BufferTarget & | Log (Facility facility, Severity severity, const char *message,...) |
| Writes a log message with the given facility and severity to this target.
|
|
BufferTarget & | Log (Entry entry) |
| Writes an Entry to this target.
|
|
void | Open (void) |
| Opens this target if it has been paused.
|
|
BufferTarget & | SetDefaultAppName (const char *app_name) |
| Sets the default app name for this target.
|
|
BufferTarget & | SetDefaultFacility (int facility) |
| Sets the default facility of the target.
|
|
BufferTarget & | SetDefaultMsgid (const char *msgid) |
| Sets the default message id for this target.
|
|
BufferTarget & | SetFilter (stumpless_filter_func_t filter) |
| Sets the filter used by this target to determine whether entries should be logged to it.
|
|
BufferTarget & | SetMask (int mask) |
| Sets the log mask of a target.
|
|
BufferTarget & | SetOption (int option) |
| Sets an option on a target.
|
|
BufferTarget & | UnsetOption (int option) |
| Unsets an option on a target.
|
|
A target that will write log messages to a provided buffer, wrapping around when the end is reached.
A NULL character will be written to the end of each message. Note that callers must handle the wrap-around case, and not assume that each read will end in a NULL character, in case a wrap-around occurs.
◆ BufferTarget() [1/2]
stumpless::BufferTarget::BufferTarget |
( |
struct stumpless_target * | equivalent | ) |
|
◆ BufferTarget() [2/2]
stumpless::BufferTarget::BufferTarget |
( |
const char * | name, |
|
|
char * | buffer, |
|
|
size_t | size ) |
Opens a buffer target for the given buffer.
- Parameters
-
name | The name of this target. |
buffer | The buffer to log events to. |
size | The number of characters buffer can hold. |
◆ ~BufferTarget()
stumpless::BufferTarget::~BufferTarget |
( |
void | | ) |
|
Closes the target and releases all memory owned by it.
Does NOT empty or free the buffer.
◆ GetDefaultAppName()
const char * stumpless::BufferTarget::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::BufferTarget::GetDefaultFacility |
( |
void | | ) |
|
Gets the default facility of this target.
- Returns
- The default facility of this target.
◆ GetDefaultMsgid()
const char * stumpless::BufferTarget::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::BufferTarget::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::BufferTarget::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::BufferTarget::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::BufferTarget::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
-
option | The 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::BufferTarget::IsOpen |
( |
void | | ) |
|
Checks to see if this target is open.
- Returns
- True if the target is open, false otherwise.
◆ Log() [1/4]
BufferTarget & stumpless::BufferTarget::Log |
( |
const char * | message, |
|
|
| ... ) |
Writes a string message to this target.
- Parameters
-
message | The 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]
Writes an Entry to this target.
- Parameters
-
- Returns
- The modified target.
◆ Log() [3/4]
Writes a log message with the given facility and severity to this target.
- Parameters
-
facility | The facility code of the message. |
severity | The severity code of the message. |
message | The 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]
BufferTarget & stumpless::BufferTarget::Log |
( |
int | priority, |
|
|
const char * | message, |
|
|
| ... ) |
Writes a log message with the given priority to this target.
- Parameters
-
priority | The 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. |
message | The 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::BufferTarget::Open |
( |
void | | ) |
|
Opens this target if it has been paused.
◆ Read()
size_t stumpless::BufferTarget::Read |
( |
char * | buffer, |
|
|
size_t | max_length ) |
Reads the next message from this target and writes it into the given buffer.
If the buffer has not been read from before messages have wrapped around, then you may only get the end of a message. To avoid this situation, you will need to read the buffer often enough to stay ahead of the written messages. Making sure that the log buffer is sufficiently sized may help with this. A terminating NULL character will always be written at the end of the output. Note that this means that if the read operation was successful but there was no message to read, the result will be 1 with a single NULL character being written to the read buffer. Available since release v2.0.0.
- Parameters
-
buffer | The buffer to write the message into. |
max_length | The maximum number of bytes to write into the provided buffer. |
- Returns
- The number of bytes written into the buffer, including the terminating NULL character.
◆ SetDefaultAppName()
BufferTarget & stumpless::BufferTarget::SetDefaultAppName |
( |
const char * | app_name | ) |
|
Sets the default app name for this target.
- Parameters
-
app_name | The new default app name, as a NULL-terminated string. |
- Returns
- The modified target.
◆ SetDefaultFacility()
BufferTarget & stumpless::BufferTarget::SetDefaultFacility |
( |
int | facility | ) |
|
Sets the default facility of the target.
- Parameters
-
facility | The default facility for the target to use. This should be a STUMPLESS_FACILITY value. |
- Returns
- The modified target.
◆ SetDefaultMsgid()
BufferTarget & stumpless::BufferTarget::SetDefaultMsgid |
( |
const char * | msgid | ) |
|
Sets the default message id for this target.
- Parameters
-
msgid | The new default message id, as a NULL-terminated string. |
- Returns
- The modified target.
◆ SetFilter()
BufferTarget & stumpless::BufferTarget::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
-
filter | The new filter to use for this target. |
- Returns
- The modified target.
◆ SetMask()
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
-
mask | The new mask to use for this target. |
- Returns
- The modified target.
◆ SetOption()
BufferTarget & stumpless::BufferTarget::SetOption |
( |
int | option | ) |
|
Sets an option on a target.
- Parameters
-
option | The option to set. This should be a STUMPLESS_OPTION value. |
- Returns
- The modified target.
◆ UnsetOption()
BufferTarget & stumpless::BufferTarget::UnsetOption |
( |
int | option | ) |
|
Unsets an option on a target.
- Parameters
-
option | The option to unset. This should be a STUMPLESS_OPTION value. |
- Returns
- The modified target.
◆ equivalent
struct stumpless_target* stumpless::BufferTarget::equivalent |
The documentation for this class was generated from the following file: