332 lines
12 KiB
C++
332 lines
12 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivFramework/LoggerServiceApi.h
|
|
*
|
|
* @brief Header file for the logger service api class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_FRAMEWORK_LOGGER_SERVICE_API_H)
|
|
#define ACTIV_FRAMEWORK_LOGGER_SERVICE_API_H
|
|
|
|
#include "ActivMiddleware/ActivFramework/External.h"
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/UInt.h"
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/SInt.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
class Address;
|
|
class Component;
|
|
class MessageBuilder;
|
|
class ScatterBufferHelper;
|
|
class HeapMessage;
|
|
class PostMessageHelper;
|
|
class ScopedAddress;
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Api to the agent's logger service.
|
|
*/
|
|
class LoggerServiceApi
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Request helper class.
|
|
*
|
|
* @param REQUEST_TYPE the request type.
|
|
* @param PARAMETERS the type of request parameters.
|
|
*/
|
|
template<MessageType REQUEST_TYPE, typename PARAMETERS>
|
|
class RequestHelper
|
|
{
|
|
public:
|
|
typedef PARAMETERS Parameters; ///< The parameters typedef.
|
|
|
|
/**
|
|
* @brief Create a new log file (or open an existing log file).
|
|
*
|
|
* @param component the component wanting to open the log file.
|
|
* @param parameters the request parameters for the log file.
|
|
* @param address reference to a scoped address object to receive the address of the log file.
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode Create(const Component &component, const Parameters ¶meters,
|
|
ScopedAddress &address);
|
|
|
|
static const MessageType REQUEST = REQUEST_TYPE; ///< The request type.
|
|
};
|
|
|
|
/**
|
|
* @brief Request parameters for opening log file
|
|
*/
|
|
class LogParameters
|
|
{
|
|
public:
|
|
/**
|
|
* @brief The basic filename for the log file. Will get decorated according to the type of log file, time periods, etc.
|
|
* If the filename is absolute, it will be created in the location specified.
|
|
* If if starts ./ or .\ (as appropriate for the platform) it will be created relative to the working directory.
|
|
* Otherwise, it is created relative to the LoggerService's default log directory.
|
|
*/
|
|
String m_fileName;
|
|
String m_header; ///< The log file header. A newline will automatically be appended.
|
|
UInt m_nBackups; ///< Number of past increments (days, months, etc) for which to keep log files.
|
|
|
|
protected:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param fileName the log file name.
|
|
*/
|
|
ACTIV_FRAMEWORK_API LogParameters(const String &fileName);
|
|
};
|
|
|
|
/**
|
|
* @brief Request parameters for opening a rolling log file. When a rolling log file reaches its maximum size,
|
|
* message logging rolls back to the beginning of the file.
|
|
*/
|
|
class RollingLogParameters : public LogParameters
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param fileName the log file name.
|
|
* @param maxFileSize the maximum size of the log file.
|
|
* @param nBackups the number of old rolling log files (with the same name) to keep.
|
|
*/
|
|
ACTIV_FRAMEWORK_API RollingLogParameters(const String &fileName, const UInt &maxFileSize, const UInt &nBackups);
|
|
|
|
UInt m_maxFileSize; ///< Maximum size of the log file.
|
|
};
|
|
|
|
/**
|
|
* @brief Request parameters for opening a time-based log file (daily, weekly, monthly). These log files are
|
|
* splittable; when the file reaches its split file size, message logging continues in a new file.
|
|
*/
|
|
class SplittableLogParameters : public LogParameters
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param fileName the log file name.
|
|
*/
|
|
ACTIV_FRAMEWORK_API SplittableLogParameters(const String &fileName);
|
|
|
|
UInt m_nIntervals; ///< Create a new log every N intervals (hour, day, week, month). Default is 1.
|
|
UInt m_maxTotalSizeOfBackupFiles; ///< Maximum total size of all associated backup files.
|
|
UInt m_splitFileSize; ///< Position at which logging should split and move to new file.
|
|
UInt m_fileType; ///< The file type. Default: FILE_TYPE_NORMAL.
|
|
SInt m_compressionLevel; ///< Compression level of the file.
|
|
};
|
|
|
|
// Available log types.
|
|
typedef RequestHelper<LOGGER_REQUEST_OPEN_ROLLING_LOG_FILE, RollingLogParameters> RollingLog;
|
|
typedef RequestHelper<LOGGER_REQUEST_OPEN_HOURLY_SPLITTABLE_LOG_FILE, SplittableLogParameters> HourlyLog;
|
|
typedef RequestHelper<LOGGER_REQUEST_OPEN_DAILY_SPLITTABLE_LOG_FILE, SplittableLogParameters> DailyLog;
|
|
typedef RequestHelper<LOGGER_REQUEST_OPEN_WEEKLY_SPLITTABLE_LOG_FILE, SplittableLogParameters> WeeklyLog;
|
|
typedef RequestHelper<LOGGER_REQUEST_OPEN_MONTHLY_SPLITTABLE_LOG_FILE, SplittableLogParameters> MonthlyLog;
|
|
|
|
/**
|
|
* @brief Log a message to a log file.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param logAddress the address of a log file.
|
|
* @param message the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, const Address &logAddress,
|
|
const String &message);
|
|
|
|
/**
|
|
* @brief Log a message to a log file.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param logAddress the address of a log file.
|
|
* @param message BoostFormat containing the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, const Address &logAddress,
|
|
const BoostFormat &message);
|
|
|
|
/**
|
|
* @brief Log a message to a log file.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param logAddress the address of a log file.
|
|
* @param pMessage the message to log.
|
|
* @param messageLength the length of the message.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, const Address &logAddress,
|
|
const void *pMessage, const size_t messageLength);
|
|
|
|
/**
|
|
* @brief Log a message to a log file.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param logAddress the address of a log file.
|
|
* @param messageBuilder containing the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, const Address &logAddress,
|
|
const MessageBuilder &messageBuilder);
|
|
|
|
/**
|
|
* @brief Log a message to a log file.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param logAddress the address of a log file.
|
|
* @param scatterBufferHelper containing the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, const Address &logAddress,
|
|
const ScatterBufferHelper &scatterBufferHelper);
|
|
|
|
/**
|
|
* @brief Log a message to a log file.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param logAddress the address of a log file.
|
|
* @param heapMessage a HeapMessage containing the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, const Address &logAddress,
|
|
HeapMessage &heapMessage);
|
|
|
|
/**
|
|
* @brief Log a message to a log file via a PostMessageHelper object.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param postMessageHelper reference to a PostMessageHelper. The message will be queued here
|
|
* and not immediately sent to the LoggerService for distribution. postMessageHelper.Flush() will
|
|
* need to be called at some point in order to push any queued messages to the LoggerService.
|
|
* @param logAddress the address of a log file.
|
|
* @param message the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, PostMessageHelper &postMessageHelper,
|
|
const Address &logAddress, const String &message);
|
|
|
|
/**
|
|
* @brief Log a message to a log file via a PostMessageHelper object.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param postMessageHelper reference to a PostMessageHelper. The message will be queued here
|
|
* and not immediately sent to the LoggerService for distribution. postMessageHelper.Flush() will
|
|
* need to be called at some point in order to push any queued messages to the LoggerService.
|
|
* @param logAddress the address of a log file.
|
|
* @param message BoostFormat containing the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, PostMessageHelper &postMessageHelper,
|
|
const Address &logAddress, const BoostFormat &message);
|
|
|
|
/**
|
|
* @brief Log a message to a log file via a PostMessageHelper object.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param postMessageHelper reference to a PostMessageHelper. The message will be queued here
|
|
* and not immediately sent to the LoggerService for distribution. postMessageHelper.Flush() will
|
|
* need to be called at some point in order to push any queued messages to the LoggerService.
|
|
* @param logAddress the address of a log file.
|
|
* @param pMessage the message to log.
|
|
* @param messageLength the length of the message.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, PostMessageHelper &postMessageHelper,
|
|
const Address &logAddress, const void *pMessage, const size_t messageLength);
|
|
|
|
/**
|
|
* @brief Log a message to a log file via a PostMessageHelper object.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param postMessageHelper reference to a PostMessageHelper. The message will be queued here
|
|
* and not immediately sent to the LoggerService for distribution. postMessageHelper.Flush() will
|
|
* need to be called at some point in order to push any queued messages to the LoggerService.
|
|
* @param logAddress the address of a log file.
|
|
* @param messageBuilder the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, PostMessageHelper &postMessageHelper,
|
|
const Address &logAddress, const MessageBuilder &messageBuilder);
|
|
|
|
/**
|
|
* @brief Log a message to a log file via a PostMessageHelper object.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param postMessageHelper reference to a PostMessageHelper. The message will be queued here
|
|
* and not immediately sent to the LoggerService for distribution. postMessageHelper.Flush() will
|
|
* need to be called at some point in order to push any queued messages to the LoggerService.
|
|
* @param logAddress the address of a log file.
|
|
* @param scatterBufferHelper the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_HEAP_EMPTY
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, PostMessageHelper &postMessageHelper,
|
|
const Address &logAddress, const ScatterBufferHelper &scatterBufferHelper);
|
|
|
|
/**
|
|
* @brief Log a message to a log file via a PostMessageHelper object.
|
|
*
|
|
* @param component that wishes to log.
|
|
* @param postMessageHelper reference to a PostMessageHelper. The message will be queued here
|
|
* and not immediately sent to the LoggerService for distribution. postMessageHelper.Flush() will
|
|
* need to be called at some point in order to push any queued messages to the LoggerService.
|
|
* @param logAddress the address of a log file.
|
|
* @param heapMessage a HeapMessage containing the message to log.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode LogMessage(const Component &component, PostMessageHelper &postMessageHelper,
|
|
const Address &logAddress, HeapMessage &heapMessage);
|
|
|
|
/**
|
|
* @brief Get the default directory used by the LoggerService.
|
|
*
|
|
* @param component
|
|
* @param directory to receive the directory.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_FRAMEWORK_API static StatusCode GetDefaultDirectory(const Component &component, String &directory);
|
|
};
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_FRAMEWORK_LOGGER_SERVICE_API_H)
|