# Environment.hpp
This File On Github
Ask A Question
API: latest
module: oatpp
#include "oatpp/core/base/Environment.hpp"
# v_buff_size
Namespace: ``
This type is the integer type capable of storing a pointer. Thus is capable of storing size of allocated memory.
Use this type to define a size for the buffer.
typedef intptr_t v_buff_size
# Logger
Interface for system-wide Logger.
All calls to OATPP_DISABLE_LOGV
, OATPP_DISABLE_LOGD
, OATPP_DISABLE_LOGI
, OATPP_DISABLE_LOGW
, OATPP_DISABLE_LOGE
will come here.
namespace oatpp { namespace base {
class Logger {}
}}
# Fields
Type | Name | Summary |
---|---|---|
v_uint32 | PRIORITY_V | Log priority V-verbouse. |
v_uint32 | PRIORITY_D | Log priority D-debug. |
v_uint32 | PRIORITY_I | Log priority I-Info. |
v_uint32 | PRIORITY_W | Log priority W-Warning. |
v_uint32 | PRIORITY_E | Log priority E-error. |
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | ~Logger | Virtual Destructor. |
void | log | Log message with priority, tag, message. |
bool | isLogPriorityEnabled | Returns wether or not a priority should be logged/printed |
v_buff_size | getMaxFormattingBufferSize | Should return the maximum amount of bytes that should be allocated for a single log message |
# Logger::PRIORITY_V
Log priority V-verbouse.
static constexpr v_uint32 PRIORITY_V = 0
# Logger::PRIORITY_D
Log priority D-debug.
static constexpr v_uint32 PRIORITY_D = 1
# Logger::PRIORITY_I
Log priority I-Info.
static constexpr v_uint32 PRIORITY_I = 2
# Logger::PRIORITY_W
Log priority W-Warning.
static constexpr v_uint32 PRIORITY_W = 3
# Logger::PRIORITY_E
Log priority E-error.
static constexpr v_uint32 PRIORITY_E = 4
# Logger::~Logger
Virtual Destructor.
virtual ~Logger() = default
# Logger::log
Log message with priority, tag, message.
- @param priority - priority channel of the message.
- @param tag - tag of the log message.
- @param message - message.
virtual void log(v_uint32 priority, const std::string& tag, const std::string& message) = 0
# Logger::isLogPriorityEnabled
Returns wether or not a priority should be logged/printed
- @param priority
- @return - true if given priority should be logged
virtual bool isLogPriorityEnabled(v_uint32 )
# Logger::getMaxFormattingBufferSize
Should return the maximum amount of bytes that should be allocated for a single log message
- @return - maximum buffer size
virtual v_buff_size getMaxFormattingBufferSize()
# LogCategory
Describes a logging category (i.e. a logging "namespace")
namespace oatpp { namespace base {
class LogCategory {}
}}
# Fields
Type | Name | Summary |
---|---|---|
const std::string | tag | The tag for this category |
bool | categoryEnabled | Generally enable or disable this category |
v_uint32 | enabledPriorities | Priorities to print that are logged in this category |
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | LogCategory | Constructs a logging category. |
void | enablePriority | Enables logging of a priorities for this category |
void | disablePriority | Disabled logging of a priorities for this category |
bool | isLogPriorityEnabled | Returns wether or not a priority of this category should be logged/printed |
# LogCategory::tag
The tag for this category
const std::string tag
# LogCategory::categoryEnabled
Generally enable or disable this category
bool categoryEnabled
# LogCategory::enabledPriorities
Priorities to print that are logged in this category
v_uint32 enabledPriorities
# LogCategory::LogCategory
Constructs a logging category.
- @param pTag - Tag of this logging category
- @param pCategoryEnabled - Enable or disable the category completely
- @param pEnabledPriorities - Bitmap of initially active logging categories.
LogCategory(std::string pTag, bool pCategoryEnabled, v_uint32 pEnabledPriorities = ((1<<Logger::PRIORITY_V) | (1<<Logger::PRIORITY_D) | (1<<Logger::PRIORITY_I) | (1<<Logger::PRIORITY_W) | (1<<Logger::PRIORITY_E)))
: tag(std::move(pTag))
, categoryEnabled(pCategoryEnabled)
, enabledPriorities(pEnabledPriorities)
# LogCategory::enablePriority
Enables logging of a priorities for this category
- @param priority - the priority level to enable
void enablePriority(v_uint32 priority)
# LogCategory::disablePriority
Disabled logging of a priorities for this category
- @param priority - the priority level to disable
void disablePriority(v_uint32 priority)
# LogCategory::isLogPriorityEnabled
Returns wether or not a priority of this category should be logged/printed
- @param priority
- @return - true if given priority should be logged
bool isLogPriorityEnabled(v_uint32 priority)
# DefaultLogger
Default Logger implementation.
namespace oatpp { namespace base {
class DefaultLogger : public Logger {}
}}
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | DefaultLogger | Constructor. |
void | log | Log message with priority, tag, message. |
void | enablePriority | Enables logging of a priorities for this instance |
void | disablePriority | Disables logging of a priority for this instance |
bool | isLogPriorityEnabled | Returns wether or not a priority should be logged/printed |
# DefaultLogger::DefaultLogger
Constructor.
- @param config - Logger config.
DefaultLogger(const Config& config = Config(
"%Y-%m-%d %H:%M:%S",
true,
(1 << PRIORITY_V) | (1 << PRIORITY_D) | (1 << PRIORITY_I) | (1 << PRIORITY_W) | (1 << PRIORITY_E)
))
# DefaultLogger::log
Log message with priority, tag, message.
- @param priority - log-priority channel of the message.
- @param tag - tag of the log message.
- @param message - message.
void log(v_uint32 priority, const std::string& tag, const std::string& message) override
# DefaultLogger::enablePriority
Enables logging of a priorities for this instance
- @param priority - the priority level to enable
void enablePriority(v_uint32 priority)
# DefaultLogger::disablePriority
Disables logging of a priority for this instance
- @param priority - the priority level to disable
void disablePriority(v_uint32 priority)
# DefaultLogger::isLogPriorityEnabled
Returns wether or not a priority should be logged/printed
- @param priority
- @return - true if given priority should be logged
bool isLogPriorityEnabled(v_uint32 priority) override
# DefaultLogger::Config
Default Logger Config.
namespace oatpp { namespace base {
class DefaultLogger : public Logger {
struct Config {}
};
}}
# Fields
Type | Name | Summary |
---|---|---|
const char* | timeFormat | Time format of the log message. If nullptr then do not print time. |
bool | printTicks | Print micro-ticks in the log message. |
v_uint32 | logMask | Log mask to enable/disable certain priorities |
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | Config | Constructor. |
# DefaultLogger::Config::timeFormat
Time format of the log message. If nullptr then do not print time.
const char* timeFormat
# DefaultLogger::Config::printTicks
Print micro-ticks in the log message.
bool printTicks
# DefaultLogger::Config::logMask
Log mask to enable/disable certain priorities
v_uint32 logMask
# DefaultLogger::Config::Config
Constructor.
- @param tfmt - time format.
- @param printMicroTicks - show ticks in microseconds.
Config(const char* tfmt, bool printMicroTicks, v_uint32 initialLogMask)
: timeFormat(tfmt)
, printTicks(printMicroTicks)
, logMask(initialLogMask)
# Environment
Class to manage application environment.
Manage object counters, manage components, and do system health-checks.
namespace oatpp { namespace base {
class Environment {}
}}
# Methods
Return Type | Name | Summary |
---|---|---|
void | init | Multiple implementations:
|
void | destroy | De-initialize environment and do basic health-checks. |
void | incObjects | increment counter of objects. |
void | decObjects | decrement counter of objects. |
v_counter | getObjectsCount | Get count of objects currently allocated and stored in the memory. |
v_counter | getObjectsCreated | Get count of objects created for a whole system lifetime. |
v_counter | getThreadLocalObjectsCount | Same as getObjectsCount() but thread_local |
v_counter | getThreadLocalObjectsCreated | Same as getObjectsCreated() but thread_local |
void | setLogger | Set environment logger. |
std::shared_ptr<Logger> | getLogger | Gets the current environment logger |
void | printCompilationConfig | Print debug information of compilation config. |
void | log | Call Logger::log() |
void | logFormatted | Multiple implementations:
|
void* | getComponent | Multiple implementations:
|
v_int64 | getMicroTickCount | Get ticks count in microseconds. |
# Environment::init
- Initialize environment and do basic health-checks.
static void init()
- Initialize environment and do basic health-checks.
- @param logger - system-wide logger.
static void init(const std::shared_ptr<Logger>& logger)
# Environment::destroy
De-initialize environment and do basic health-checks. Check for memory leaks.
static void destroy()
# Environment::incObjects
increment counter of objects.
static void incObjects()
# Environment::decObjects
decrement counter of objects.
static void decObjects()
# Environment::getObjectsCount
Get count of objects currently allocated and stored in the memory.
- @return
static v_counter getObjectsCount()
# Environment::getObjectsCreated
Get count of objects created for a whole system lifetime.
- @return - count of objects.
static v_counter getObjectsCreated()
# Environment::getThreadLocalObjectsCount
Same as getObjectsCount()
but thread_local
- @return - count of objects.
0 - if built with-DOATPP_COMPAT_BUILD_NO_THREAD_LOCAL
flag
static v_counter getThreadLocalObjectsCount()
# Environment::getThreadLocalObjectsCreated
Same as getObjectsCreated()
but thread_local
- @return - count of objects.
0 - if built with-DOATPP_COMPAT_BUILD_NO_THREAD_LOCAL
flag
static v_counter getThreadLocalObjectsCreated()
# Environment::setLogger
Set environment logger.
- @param logger - system-wide logger.
static void setLogger(const std::shared_ptr<Logger>& logger)
# Environment::getLogger
Gets the current environment logger
- @return - current logger
static std::shared_ptr<Logger> getLogger()
# Environment::printCompilationConfig
Print debug information of compilation config.
Print values for:
- OATPP_DISABLE_ENV_OBJECT_COUNTERS
- OATPP_THREAD_HARDWARE_CONCURRENCY
static void printCompilationConfig()
# Environment::log
Call Logger::log()
- @param priority - log-priority channel of the message.
- @param tag - tag of the log message.
- @param message - message.
static void log(v_uint32 priority, const std::string& tag, const std::string& message)
# Environment::logFormatted
- Format message and call
Logger::log()
Message is formatted usingvsnprintf
method.- @param priority - log-priority channel of the message.
- @param tag - tag of the log message.
- @param message - message.
- @param ... - format arguments.
static void logFormatted(v_uint32 priority, const std::string& tag, const char* message, ...)
- Format message and call
Logger::log()
Message is formatted usingvsnprintf
method.- @param priority - log-priority channel of the message.
- @param category - category of the log message.
- @param message - message.
- @param ... - format arguments.
static void logFormatted(v_uint32 priority, const LogCategory& category, const char* message, ...)
# Environment::getComponent
- Get component object by typeName.
- @param typeName - type name of the component.
- @return - pointer to a component object.
static void* getComponent(const std::string& typeName)
- Get component object by typeName and componentName.
- @param typeName - type name of the component.
- @param componentName - component qualifier name.
- @return - pointer to a component object.
static void* getComponent(const std::string& typeName, const std::string& componentName)
# Environment::getMicroTickCount
Get ticks count in microseconds.
- @return - ticks count in microseconds.
static v_int64 getMicroTickCount()
# Environment::Component
Class representing system component.
- @tparam T - component type.
namespace oatpp { namespace base {
class Environment {
template <typename T>
class Component {}
};
}}
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | Component | Multiple implementations:
|
[none] | ~Component | Non-virtual Destructor. |
T | getObject | Get object stored in the component. |
# Environment::Component::Component
- Constructor.
- @param name - component name.
- @param object - component object.
Component(const std::string& name, const T& object) : m_type(typeid(T).name()) , m_name(name) , m_object(object)
- Constructor.
- @param object - component object.
Component(const T& object) : Component("NoName", object)
# Environment::Component::~Component
Non-virtual Destructor.
~Component()
# Environment::Component::getObject
Get object stored in the component.
- @return - object.
T getObject()
# OATPP_ASSERT
Default oatpp assert method.
- @param EXP - expression that must be
true
.
#define OATPP_ASSERT(EXP)
# OATPP_DECLARE_LOG_CATEGORY
Convenience macro to declare a logging category directly in a class header.
- @param NAME - variable-name of the category which is later used to reference the category.
#define OATPP_DECLARE_LOG_CATEGORY(NAME)
# OATPP_LOG_CATEGORY
Convenience macro to implement a logging category directly in a class header.
- @param NAME - variable-name of the category which is later used to reference the category.
- @param TAG - tag printed with each message printed usig this category.
- @param ENABLED - enable or disable a category (bool).
#define OATPP_LOG_CATEGORY(NAME, TAG, ENABLED)
# OATPP_LOGV
Log message with Logger::PRIORITY_V
To disable this log compile oatpp with #define OATPP_DISABLE_LOGV
- @param TAG - message tag.
- @param ...(1) - message.
- @param ... - optional format parameter.
#define OATPP_LOGV(TAG, ...)
# OATPP_LOGD
Log message with Logger::PRIORITY_D
To disable this log compile oatpp with #define OATPP_DISABLE_LOGD
- @param TAG - message tag.
- @param ...(1) - message.
- @param ... - optional format parameter.
#define OATPP_LOGD(TAG, ...)
# OATPP_LOGI
Log message with Logger::PRIORITY_I
To disable this log compile oatpp with #define OATPP_DISABLE_LOGI
- @param TAG - message tag.
- @param ...(1) - message.
- @param ... - optional format parameter.
#define OATPP_LOGI(TAG, ...)
# OATPP_LOGW
Log message with Logger::PRIORITY_W
To disable this log compile oatpp with #define OATPP_DISABLE_LOGW
- @param TAG - message tag.
- @param ...(1) - message.
- @param ... - optional format parameter.
#define OATPP_LOGW(TAG, ...)
# OATPP_LOGE
Log message with Logger::PRIORITY_E
To disable this log compile oatpp with #define OATPP_DISABLE_LOGE
- @param TAG - message tag.
- @param ...(1) - message.
- @param ... - optional format parameter.
#define OATPP_LOGE(TAG, ...)