Photon Common Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
logging.h File Reference

Logging functions. More...

#include "Common/Log/logger_fwd.h"
#include "Common/Log/ELogLevel.h"
#include "Common/config.h"
#include "Common/macro.h"
#include <string>
#include <vector>
#include <cstddef>
#include <format>

Go to the source code of this file.

Classes

struct  ph::LogGroup
 
class  ph::LogGroups
 

Namespaces

namespace  ph
 The root for all renderer implementations.
 
namespace  ph::detail
 Implementation detail mainly for internal usages.
 
namespace  ph::detail::core_logging
 Core logging functionalities. Most logs will output information (logs) via a main logger, which we refer to as "core logger". This namespace contains implementation details for core logging functionalities.
 

Macros

#define PH_DECLARE_LOG_GROUP(groupName)    const ::ph::Logger& internal_impl_logger_access_##groupName()
 Declares a logger. The logger should be defined using PH_DEFINE_LOG_GROUP() somewhere in the source (preferably in a .cpp file).
 
#define PH_DEFINE_LOG_GROUP(groupName, category)
 Defines a logger.
 
#define PH_DEFINE_INLINE_LOG_GROUP(groupName, category)
 
#define PH_DEFINE_INTERNAL_LOG_GROUP(groupName, category)
 Defines a logger that is private to a .cpp file. Can only appear one time in a translation unit, preferably in a .cpp file.
 
#define PH_DEFINE_EXTERNAL_LOG_GROUP(groupName, category)   PH_DEFINE_INLINE_LOG_GROUP(groupName, category)
 Defines a public logger in a header file. The logger will be usable anywhere that includes the header file containing this call.
 
#define PH_LOG_RAW_STRING_TO_CORE_LOGGER(groupName, level, rawStringExpr)
 
#define PH_LOG_FORMAT_STRING_TO_CORE_LOGGER(groupName, level, formatString, ...)
 
#define PH_DEBUG_LOG_STRING(groupName, rawString)   PH_NO_OP()
 
#define PH_DEBUG_LOG_STRING_ONCE(groupName, rawString)   PH_NO_OP()
 
#define PH_DEBUG_LOG(groupName, formatString, ...)   PH_NO_OP()
 
#define PH_DEBUG_LOG_ONCE(groupName, formatString, ...)   PH_NO_OP()
 
#define PH_LOG_STRING(groupName, level, rawString)   PH_LOG_RAW_STRING_TO_CORE_LOGGER(groupName, level, rawString)
 
#define PH_LOG(groupName, level, formatString, ...)   PH_LOG_FORMAT_STRING_TO_CORE_LOGGER(groupName, level, formatString, __VA_ARGS__)
 
#define PH_DEFAULT_DEBUG_LOG_STRING(rawString, ...)   PH_NO_OP()
 A set of helper utility macros to log using Photon renderer's default log group.
 
#define PH_DEFAULT_DEBUG_LOG_STRING_ONCE(rawString, ...)   PH_NO_OP()
 
#define PH_DEFAULT_DEBUG_LOG(formatString, ...)   PH_NO_OP()
 
#define PH_DEFAULT_DEBUG_LOG_ONCE(formatString, ...)   PH_NO_OP()
 
#define PH_DEFAULT_LOG_STRING(level, rawString)   PH_LOG_STRING(PhotonRenderer, level, rawString)
 
#define PH_DEFAULT_LOG(level, formatString, ...)   PH_LOG(PhotonRenderer, level, formatString, __VA_ARGS__)
 

Functions

LogGroups ph::get_core_log_groups ()
 
void ph::detail::core_logging::init ()
 Initializes core logging functionalities. Any logging is only valid after calling init().
 
void ph::detail::core_logging::exit ()
 Terminates core logging functionalities. Cleanup after logging is finished.
 
Loggerph::detail::core_logging::get_logger ()
 Get the core logger.
 
std::size_t ph::detail::core_logging::add_log_group (std::string_view groupName, std::string_view category="")
 Add a log group to the core logger.
 
void ph::detail::core_logging::log_to_logger (const Logger &logger, std::string_view groupName, ELogLevel logLevel, std::string_view logMessage)
 Log information to the specified logger.
 
 ph::PH_DECLARE_LOG_GROUP (PhotonRenderer)
 

Detailed Description

Logging functions.

Note on loggers: All logging functionalities are thread-safe when using pre-defined macros. It is not advisible to log in class dtor, especially for static instances as they may live outside of engine's lifetime. Also make sure not to call any logging functions when the logger is not initialized.

Macro Definition Documentation

◆ PH_DEBUG_LOG

#define PH_DEBUG_LOG ( groupName,
formatString,
... )   PH_NO_OP()

◆ PH_DEBUG_LOG_ONCE

#define PH_DEBUG_LOG_ONCE ( groupName,
formatString,
... )   PH_NO_OP()

◆ PH_DEBUG_LOG_STRING

#define PH_DEBUG_LOG_STRING ( groupName,
rawString )   PH_NO_OP()

◆ PH_DEBUG_LOG_STRING_ONCE

#define PH_DEBUG_LOG_STRING_ONCE ( groupName,
rawString )   PH_NO_OP()

◆ PH_DECLARE_LOG_GROUP

#define PH_DECLARE_LOG_GROUP ( groupName)     const ::ph::Logger& internal_impl_logger_access_##groupName()

Declares a logger. The logger should be defined using PH_DEFINE_LOG_GROUP() somewhere in the source (preferably in a .cpp file).

◆ PH_DEFAULT_DEBUG_LOG

#define PH_DEFAULT_DEBUG_LOG ( formatString,
... )   PH_NO_OP()

◆ PH_DEFAULT_DEBUG_LOG_ONCE

#define PH_DEFAULT_DEBUG_LOG_ONCE ( formatString,
... )   PH_NO_OP()

◆ PH_DEFAULT_DEBUG_LOG_STRING

#define PH_DEFAULT_DEBUG_LOG_STRING ( rawString,
... )   PH_NO_OP()

A set of helper utility macros to log using Photon renderer's default log group.

Note
Default log group macros are for uses in the ph namespace. For general usages, use the custom log group macros.

◆ PH_DEFAULT_DEBUG_LOG_STRING_ONCE

#define PH_DEFAULT_DEBUG_LOG_STRING_ONCE ( rawString,
... )   PH_NO_OP()

◆ PH_DEFAULT_LOG

#define PH_DEFAULT_LOG ( level,
formatString,
... )   PH_LOG(PhotonRenderer, level, formatString, __VA_ARGS__)

◆ PH_DEFAULT_LOG_STRING

#define PH_DEFAULT_LOG_STRING ( level,
rawString )   PH_LOG_STRING(PhotonRenderer, level, rawString)

◆ PH_DEFINE_EXTERNAL_LOG_GROUP

#define PH_DEFINE_EXTERNAL_LOG_GROUP ( groupName,
category )   PH_DEFINE_INLINE_LOG_GROUP(groupName, category)

Defines a public logger in a header file. The logger will be usable anywhere that includes the header file containing this call.

◆ PH_DEFINE_INLINE_LOG_GROUP

#define PH_DEFINE_INLINE_LOG_GROUP ( groupName,
category )
Value:
inline const ::ph::Logger& internal_impl_logger_access_##groupName()\
{\
static const std::size_t logGroupIndex = ::ph::detail::core_logging::add_log_group(#groupName, #category);\
\
return ::ph::detail::core_logging::get_logger();\
}
std::size_t add_log_group(std::string_view groupName, std::string_view category="")
Add a log group to the core logger.
Definition logging.cpp:134

◆ PH_DEFINE_INTERNAL_LOG_GROUP

#define PH_DEFINE_INTERNAL_LOG_GROUP ( groupName,
category )
Value:
namespace\
{\
PH_DEFINE_INLINE_LOG_GROUP(groupName, category);\
}

Defines a logger that is private to a .cpp file. Can only appear one time in a translation unit, preferably in a .cpp file.

◆ PH_DEFINE_LOG_GROUP

#define PH_DEFINE_LOG_GROUP ( groupName,
category )
Value:
const ::ph::Logger& internal_impl_logger_access_##groupName()\
{\
static const std::size_t logGroupIndex = ::ph::detail::core_logging::add_log_group(#groupName, #category);\
\
return ::ph::detail::core_logging::get_logger();\
}

Defines a logger.

◆ PH_LOG

#define PH_LOG ( groupName,
level,
formatString,
... )   PH_LOG_FORMAT_STRING_TO_CORE_LOGGER(groupName, level, formatString, __VA_ARGS__)

◆ PH_LOG_FORMAT_STRING_TO_CORE_LOGGER

#define PH_LOG_FORMAT_STRING_TO_CORE_LOGGER ( groupName,
level,
formatString,
... )
Value:
groupName,\
level,\
std::format(formatString __VA_OPT__(,) __VA_ARGS__))
#define PH_LOG_RAW_STRING_TO_CORE_LOGGER(groupName, level, rawStringExpr)
Definition logging.h:122

◆ PH_LOG_RAW_STRING_TO_CORE_LOGGER

#define PH_LOG_RAW_STRING_TO_CORE_LOGGER ( groupName,
level,
rawStringExpr )
Value:
do\
{\
constexpr auto logLevel = ::ph::ELogLevel::level;\
const auto rawString = rawStringExpr;\
if constexpr(::ph::is_once(logLevel))\
{\
static const bool PH_CONCAT_2(dummy, __LINE__) = [&]()\
{\
::ph::detail::core_logging::log_to_logger(\
internal_impl_logger_access_##groupName(),\
#groupName,\
logLevel,\
rawString);\
return true;\
}();\
}\
else\
{\
::ph::detail::core_logging::log_to_logger(\
internal_impl_logger_access_##groupName(),\
#groupName,\
logLevel,\
rawString);\
}\
} while(0)
#define PH_CONCAT_2(a, b)
Definition macro.h:8
constexpr bool is_once(const ELogLevel logLevel)
Definition ELogLevel.h:20

◆ PH_LOG_STRING

#define PH_LOG_STRING ( groupName,
level,
rawString )   PH_LOG_RAW_STRING_TO_CORE_LOGGER(groupName, level, rawString)