181#include "vtkSetGet.h"
190#if defined(__clang__) || defined(__GNUC__)
193#define VTK_PRINTF_LIKE(fmtarg, firstvararg) \
194 __attribute__((__format__(__printf__, fmtarg, firstvararg)))
195#define VTK_FORMAT_STRING_TYPE const char*
196#elif defined(_MSC_VER)
197#define VTK_PRINTF_LIKE(fmtarg, firstvararg)
198#define VTK_FORMAT_STRING_TYPE _In_z_ _Printf_format_string_ const char*
200#define VTK_PRINTF_LIKE(fmtarg, firstvararg)
201#define VTK_FORMAT_STRING_TYPE const char*
204VTK_ABI_NAMESPACE_BEGIN
214 VERBOSITY_INVALID = -10,
219 VERBOSITY_ERROR = -2,
220 VERBOSITY_WARNING = -1,
240 VERBOSITY_TRACE = +9,
283 static void Init(
int& argc,
char* argv[],
const char* verbosity_flag =
"-v");
423#if !defined(__WRAP__)
436#if defined(_MSC_VER) && _MSC_VER > 1800
439 : Internals(other.Internals)
441 other.Internals =
nullptr;
451 LSInternals* Internals;
495#define vtkVLogF(level, ...) \
496 ((level) > vtkLogger::GetCurrentVerbosityCutoff()) \
498 : vtkLogger::LogF(level, __FILE__, __LINE__, __VA_ARGS__)
499#define vtkLogF(verbosity_name, ...) vtkVLogF(vtkLogger::VERBOSITY_##verbosity_name, __VA_ARGS__)
500#define vtkVLog(level, x) \
503 if ((level) <= vtkLogger::GetCurrentVerbosityCutoff()) \
505 vtkOStrStreamWrapper::EndlType const endl; \
506 vtkOStrStreamWrapper::UseEndl(endl); \
507 vtkOStrStreamWrapper vtkmsg; \
509 vtkLogger::Log(level, __FILE__, __LINE__, vtkmsg.str()); \
510 vtkmsg.rdbuf()->freeze(0); \
513#define vtkLog(verbosity_name, x) vtkVLog(vtkLogger::VERBOSITY_##verbosity_name, x)
529#define vtkVLogIfF(level, cond, ...) \
530 ((level) > vtkLogger::GetCurrentVerbosityCutoff() || (cond) == false) \
532 : vtkLogger::LogF(level, __FILE__, __LINE__, __VA_ARGS__)
534#define vtkLogIfF(verbosity_name, cond, ...) \
535 vtkVLogIfF(vtkLogger::VERBOSITY_##verbosity_name, cond, __VA_ARGS__)
537#define vtkVLogIf(level, cond, x) \
540 if ((level) <= vtkLogger::GetCurrentVerbosityCutoff() && (cond)) \
542 vtkOStrStreamWrapper::EndlType endl; \
543 vtkOStrStreamWrapper::UseEndl(endl); \
544 vtkOStrStreamWrapper vtkmsg; \
546 vtkLogger::Log(level, __FILE__, __LINE__, vtkmsg.str()); \
547 vtkmsg.rdbuf()->freeze(0); \
550#define vtkLogIf(verbosity_name, cond, x) vtkVLogIf(vtkLogger::VERBOSITY_##verbosity_name, cond, x)
553#define VTKLOG_CONCAT_IMPL(s1, s2) s1##s2
554#define VTKLOG_CONCAT(s1, s2) VTKLOG_CONCAT_IMPL(s1, s2)
555#define VTKLOG_ANONYMOUS_VARIABLE(x) VTKLOG_CONCAT(x, __LINE__)
557#define vtkVLogScopeF(level, ...) \
558 auto VTKLOG_ANONYMOUS_VARIABLE(msg_context) = ((level) > vtkLogger::GetCurrentVerbosityCutoff()) \
559 ? vtkLogger::LogScopeRAII() \
560 : vtkLogger::LogScopeRAII(level, __FILE__, __LINE__, __VA_ARGS__)
562#define vtkLogScopeF(verbosity_name, ...) \
563 vtkVLogScopeF(vtkLogger::VERBOSITY_##verbosity_name, __VA_ARGS__)
565#define vtkLogScopeFunction(verbosity_name) vtkLogScopeF(verbosity_name, "%s", __func__)
566#define vtkVLogScopeFunction(level) vtkVLogScopeF(level, "%s", __func__)
573#define vtkLogStartScope(verbosity_name, id) \
574 vtkLogger::StartScope(vtkLogger::VERBOSITY_##verbosity_name, id, __FILE__, __LINE__)
575#define vtkLogEndScope(id) vtkLogger::EndScope(id)
577#define vtkLogStartScopeF(verbosity_name, id, ...) \
578 vtkLogger::StartScopeF(vtkLogger::VERBOSITY_##verbosity_name, id, __FILE__, __LINE__, __VA_ARGS__)
580#define vtkVLogStartScope(level, id) vtkLogger::StartScope(level, id, __FILE__, __LINE__)
581#define vtkVLogStartScopeF(level, id, ...) \
582 vtkLogger::StartScopeF(level, id, __FILE__, __LINE__, __VA_ARGS__)
590#define vtkLogIdentifier(vtkobject) vtkLogger::GetIdentifier(vtkobject).c_str()
a simple class to control print indentation
LogScopeRAII(vtkLogger::Verbosity verbosity, const char *fname, unsigned int lineno, VTK_FORMAT_STRING_TYPE format,...) VTK_PRINTF_LIKE(5
LogScopeRAII(LogScopeRAII &&)=default
logging framework for use in VTK and in applications based on VTK
static bool EnableUnsafeSignalHandler
Flag to enable/disable the logging frameworks printing of a stack trace when catching signals,...
static bool EnableSigintHandler
static Verbosity ConvertToVerbosity(int value)
Convenience function to convert an integer to matching verbosity level.
static bool EnableSigtermHandler
static bool EnableSigsegvHandler
static bool EnableSigfpeHandler
void(*)(void *user_data) CloseHandlerCallbackT
Callback handle types.
void(*)(void *user_data, const Message &message) LogHandlerCallbackT
Callback handle types.
static bool EnableSigabrtHandler
static bool RemoveCallback(const char *id)
Remove a callback using the id specified.
static std::string GetIdentifier(vtkObjectBase *obj)
Returns a printable string for a vtkObjectBase instance.
static void EndScope(const char *id)
vtkBaseTypeMacro(vtkLogger, vtkObjectBase)
static std::string GetThreadName()
Get/Set the name to identify the current thread in the log output.
static void SetInternalVerbosityLevel(Verbosity level)
Set internal messages verbosity level.
void(*)(void *user_data) FlushHandlerCallbackT
Callback handle types.
static void AddCallback(const char *id, LogHandlerCallbackT callback, void *user_data, Verbosity verbosity, CloseHandlerCallbackT on_close=nullptr, FlushHandlerCallbackT on_flush=nullptr)
Add a callback to call on each log message with a verbosity less or equal to the given one.
static bool IsEnabled()
Returns true if VTK is built with logging support enabled.
static void SetThreadName(const std::string &name)
Get/Set the name to identify the current thread in the log output.
static Verbosity ConvertToVerbosity(const char *text)
Convenience function to convert a string to matching verbosity level.
static bool EnableSigbusHandler
static void Init()
Initializes logging.
static void EndLogToFile(const char *path)
Stop logging to a file at the given path.
static void Init(int &argc, char *argv[], const char *verbosity_flag="-v")
Initializes logging.
static void Log(Verbosity verbosity, VTK_FILEPATH const char *fname, unsigned int lineno, const char *txt)
static void SetStderrVerbosity(Verbosity level)
Set the verbosity level for the output logged to stderr.
FileMode
Support log file modes: TRUNCATE truncates the file clearing any existing contents while APPEND appen...
static void LogF(Verbosity verbosity, VTK_FILEPATH const char *fname, unsigned int lineno, VTK_FORMAT_STRING_TYPE format,...) VTK_PRINTF_LIKE(4
static Verbosity GetCurrentVerbosityCutoff()
Returns the maximum verbosity of all log outputs.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static bool EnableSigillHandler
static void StartScope(Verbosity verbosity, const char *id, VTK_FILEPATH const char *fname, unsigned int lineno)
static void LogToFile(const char *path, FileMode filemode, Verbosity verbosity)
Enable logging to a file at the given path.
abstract base class for most VTK objects
void operator=(const vtkObjectBase &)
The message structure that is passed to custom callbacks registered using vtkLogger::AddCallback.
#define VTK_FORMAT_STRING_TYPE
#define VTK_PRINTF_LIKE(fmtarg, firstvararg)