You.i Engine
CYILogPolicy Class Referenceabstract

Detailed Description

The policy class is responsible for emitting log information in a specific format through a custom output device. By default, it uses the console, but file and network logging are also good examples. The format of the logged message can be controlled through the use of a preferences object.

The following is an example of the attributes and associated values that are understood by the policy and which can be set in your logging preferences file:

TAG_CUSTOM1 = INFO TAG_CUSTOM2 = ERROR

REPORT_TIME_STAMP = ON REPORT_CLASS_NAME = OFF REPORT_FUNCTION_NAME = OFF REPORT_LINE_NUMBER = OFF REPORT_SEVERITY = OFF REPORT_TAGNAME = OFF

The tag name "TAG_GENERAL" is a reserved tag name which allows a tag severity to be applied to all logging statements that are sent to sent to the logger. The severity level can also be controlled independently through custom tag names sent to the logger, which would take the form: "TAG_<NAME> = <SEVERITY>". Supported values for severity are listed below:

FATAL (ranking of 0) ERROR (ranking of 1) WARNING (ranking of 2) INFO (ranking of 3) DEBUG (ranking of 4)

When you want to filter log statements by severity, specify the highest ranking severity you want reported. For example, specifying a severity rank of WARNING, would filter the logs such that only log statements reported with YI_LOGW, YI_LOGE, and YI_LOGF would be reported. If you want the INFO and higher ranks to be shown, then specify a higher rank in the preferences file.

The "REPORT_<ATTRIBUTE> = <VALUE>" propety can be used to add more information to the log for each logging statement. Supported values for reporting are listed below:

ON OFF

The default configuration for the logger defaults to the following:

TAG_GENERAL = ERROR

REPORT_TIME_STAMP = ON REPORT_CLASS_NAME = ON REPORT_FUNCTION_NAME = ON REPORT_LINE_NUMBER = ON REPORT_SEVERITY = ON REPORT_TAGNAME = ON

#include <logging/YiLogPolicy.h>

Inheritance diagram for CYILogPolicy:

Public Member Functions

 CYILogPolicy ()
 
virtual ~CYILogPolicy ()
 
virtual void Open ()=0
 
virtual void Close ()=0
 
virtual bool IsOpen () const =0
 
void PostWrite (YI_LOGGING_PARAMS &loggingParams)
 
void SetPreferences (const std::shared_ptr< CYIPreferences > &pPrefs)
 
const std::shared_ptr< CYIPreferences > & GetPreferences () const
 
void UpdateConfigMonitor () const
 
void SetWriteDirectEnabled (bool bEnabled)
 
bool IsWriteDirectEnabled () const
 
void SetUseLinesCache (bool bUseLinesCache)
 
std::vector< CYIStringGetLastLoggedLines (uint32_t uLinesCount=std::numeric_limits< uint32_t >::max()) const
 

Protected Member Functions

void EnableTimeStamp ()
 
void EnableClassName ()
 
void EnableLineNumber ()
 
void EnableSeverity ()
 
void EnableTagName ()
 
void DisableTimeStamp ()
 
void DisableClassName ()
 
void DisableLineNumber ()
 
void DisableSeverity ()
 
void DisableTagName ()
 
virtual CYIString BuildLogStatement (const CYIString &logStatement, const YI_LOGGING_PARAMS &params)
 

Protected Attributes

CYIConcurrentQueue< YI_LOGGING_PARAMSm_logQueue
 
uint32_t m_uAttributeCache
 

Friends

class CYILogger
 
class CYILoggerPriv
 
class CYILoggingThread
 
class CYILoggerCrashHandler
 

Constructor & Destructor Documentation

CYILogPolicy::CYILogPolicy ( )

Default constructor.

virtual CYILogPolicy::~CYILogPolicy ( )
virtual

Destructor.

Member Function Documentation

virtual CYIString CYILogPolicy::BuildLogStatement ( const CYIString logStatement,
const YI_LOGGING_PARAMS params 
)
protectedvirtual

Builds the log message based on the logging attribute preferences and the available logging parameters. The logStatement is the massaged logging message after the variadic parameters have been handled.

virtual void CYILogPolicy::Close ( )
pure virtual

Close command for the specific policy. The close command should be used to terminate and clean up any open resources.

Implemented in CYIConsoleLogPolicy, CYIAndroidLogPolicy, CYIAppleLogPolicy, and CYITizenNaClLogPolicy.

void CYILogPolicy::DisableClassName ( )
protected
void CYILogPolicy::DisableLineNumber ( )
protected
void CYILogPolicy::DisableSeverity ( )
protected
void CYILogPolicy::DisableTagName ( )
protected
void CYILogPolicy::DisableTimeStamp ( )
protected
void CYILogPolicy::EnableClassName ( )
protected
void CYILogPolicy::EnableLineNumber ( )
protected
void CYILogPolicy::EnableSeverity ( )
protected
void CYILogPolicy::EnableTagName ( )
protected
void CYILogPolicy::EnableTimeStamp ( )
protected
std::vector<CYIString> CYILogPolicy::GetLastLoggedLines ( uint32_t  uLinesCount = std::numeric_limits< uint32_t >::max()) const

Returns the last uLinesCount lines that were logged through this log policy. Fewer than uLinesCount lines may be returned if the cache does not contain that many lines. Will return an empty vector if usage of the lines cache is not enabled.

See also
SetUseLinesCache
const std::shared_ptr<CYIPreferences>& CYILogPolicy::GetPreferences ( ) const

Returns the logging preferences currently being used.

virtual bool CYILogPolicy::IsOpen ( ) const
pure virtual

Returns true if the policy has been opened.

Implemented in CYIAndroidLogPolicy, CYIAppleLogPolicy, CYIConsoleLogPolicy, and CYITizenNaClLogPolicy.

bool CYILogPolicy::IsWriteDirectEnabled ( ) const

Returns true if direct logging is enabled.

virtual void CYILogPolicy::Open ( )
pure virtual

Open command for the specific policy. The open command should be used to initialize or establish an open channel to the logging destination.

Implemented in CYIConsoleLogPolicy, CYIAndroidLogPolicy, CYIAppleLogPolicy, and CYITizenNaClLogPolicy.

void CYILogPolicy::PostWrite ( YI_LOGGING_PARAMS loggingParams)

Adds the log message to the message queue. The log message will be added to the queue and any filtering and formatting occurs before the message enters the queue. This operation is thread safe.

Note
The formatted message may be set to the YI_LOGGING_PARAMS::m_formattedLogMessage field of loggingParams.
void CYILogPolicy::SetPreferences ( const std::shared_ptr< CYIPreferences > &  pPrefs)

Sets the preferences for this policy. The preferences dictate what information will be contained in the log message and how the messages should be filtered. These preferences are universal across all policy writers.

void CYILogPolicy::SetUseLinesCache ( bool  bUseLinesCache)

Enables or disables the use of the lines cache. The lines cache keeps in memory the last 500 lines that were logged through this policy (but only up to 128kb).

void CYILogPolicy::SetWriteDirectEnabled ( bool  bEnabled)

Indicates to the logger that the policy wants to perform log writes.

void CYILogPolicy::UpdateConfigMonitor ( ) const

Updates the policy configuration monitor.

Friends And Related Function Documentation

friend class CYILogger
friend
friend class CYILoggerCrashHandler
friend
friend class CYILoggerPriv
friend
friend class CYILoggingThread
friend

Member Data Documentation

CYIConcurrentQueue<YI_LOGGING_PARAMS> CYILogPolicy::m_logQueue
protected

The shared logging queue used by the policy and the log writing thread.

uint32_t CYILogPolicy::m_uAttributeCache
protected

Caches the pre-parsed log message attribute. It is only built when the preferences are set.


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