173#include "vtkSetGet.h"
182#if defined(__clang__) || defined(__GNUC__)
185#define VTK_PRINTF_LIKE(fmtarg, firstvararg) \
186 __attribute__((__format__(__printf__, fmtarg, firstvararg)))
187#define VTK_FORMAT_STRING_TYPE const char*
188#elif defined(_MSC_VER)
189#define VTK_PRINTF_LIKE(fmtarg, firstvararg)
190#define VTK_FORMAT_STRING_TYPE _In_z_ _Printf_format_string_ const char*
192#define VTK_PRINTF_LIKE(fmtarg, firstvararg)
193#define VTK_FORMAT_STRING_TYPE const char*
205 VERBOSITY_INVALID = -10,
210 VERBOSITY_ERROR = -2,
211 VERBOSITY_WARNING = -1,
231 VERBOSITY_TRACE = +9,
274 static void Init(
int& argc,
char* argv[],
const char* verbosity_flag =
"-v");
414#if !defined(__WRAP__)
427#if defined(_MSC_VER) && _MSC_VER > 1800
430 : Internals(other.Internals)
432 other.Internals =
nullptr;
442 LSInternals* Internals;
462 static std::string ThreadName;
480#define vtkVLogF(level, ...) \
481 ((level) > vtkLogger::GetCurrentVerbosityCutoff()) \
483 : vtkLogger::LogF(level, __FILE__, __LINE__, __VA_ARGS__)
484#define vtkLogF(verbosity_name, ...) vtkVLogF(vtkLogger::VERBOSITY_##verbosity_name, __VA_ARGS__)
485#define vtkVLog(level, x) \
486 if ((level) <= vtkLogger::GetCurrentVerbosityCutoff()) \
488 vtkOStrStreamWrapper::EndlType endl; \
489 vtkOStrStreamWrapper::UseEndl(endl); \
490 vtkOStrStreamWrapper vtkmsg; \
492 vtkLogger::Log(level, __FILE__, __LINE__, vtkmsg.str()); \
493 vtkmsg.rdbuf()->freeze(0); \
495#define vtkLog(verbosity_name, x) vtkVLog(vtkLogger::VERBOSITY_##verbosity_name, x)
511#define vtkVLogIfF(level, cond, ...) \
512 ((level) > vtkLogger::GetCurrentVerbosityCutoff() || (cond) == false) \
514 : vtkLogger::LogF(level, __FILE__, __LINE__, __VA_ARGS__)
516#define vtkLogIfF(verbosity_name, cond, ...) \
517 vtkVLogIfF(vtkLogger::VERBOSITY_##verbosity_name, cond, __VA_ARGS__)
519#define vtkVLogIf(level, cond, x) \
520 if ((level) <= vtkLogger::GetCurrentVerbosityCutoff() && (cond)) \
522 vtkOStrStreamWrapper::EndlType endl; \
523 vtkOStrStreamWrapper::UseEndl(endl); \
524 vtkOStrStreamWrapper vtkmsg; \
526 vtkLogger::Log(level, __FILE__, __LINE__, vtkmsg.str()); \
527 vtkmsg.rdbuf()->freeze(0); \
529#define vtkLogIf(verbosity_name, cond, x) vtkVLogIf(vtkLogger::VERBOSITY_##verbosity_name, cond, x)
532#define VTKLOG_CONCAT_IMPL(s1, s2) s1##s2
533#define VTKLOG_CONCAT(s1, s2) VTKLOG_CONCAT_IMPL(s1, s2)
534#define VTKLOG_ANONYMOUS_VARIABLE(x) VTKLOG_CONCAT(x, __LINE__)
536#define vtkVLogScopeF(level, ...) \
537 auto VTKLOG_ANONYMOUS_VARIABLE(msg_context) = ((level) > vtkLogger::GetCurrentVerbosityCutoff()) \
538 ? vtkLogger::LogScopeRAII() \
539 : vtkLogger::LogScopeRAII(level, __FILE__, __LINE__, __VA_ARGS__)
541#define vtkLogScopeF(verbosity_name, ...) \
542 vtkVLogScopeF(vtkLogger::VERBOSITY_##verbosity_name, __VA_ARGS__)
544#define vtkLogScopeFunction(verbosity_name) vtkLogScopeF(verbosity_name, "%s", __func__)
545#define vtkVLogScopeFunction(level) vtkVLogScopeF(level, "%s", __func__)
552#define vtkLogStartScope(verbosity_name, id) \
553 vtkLogger::StartScope(vtkLogger::VERBOSITY_##verbosity_name, id, __FILE__, __LINE__)
554#define vtkLogEndScope(id) vtkLogger::EndScope(id)
556#define vtkLogStartScopeF(verbosity_name, id, ...) \
557 vtkLogger::StartScopeF(vtkLogger::VERBOSITY_##verbosity_name, id, __FILE__, __LINE__, __VA_ARGS__)
559#define vtkVLogStartScope(level, id) vtkLogger::StartScope(level, id, __FILE__, __LINE__)
560#define vtkVLogStartScopeF(level, id, ...) \
561 vtkLogger::StartScopeF(level, id, __FILE__, __LINE__, __VA_ARGS__)
569#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 Verbosity ConvertToVerbosity(int value)
Convenience function to convert an integer to matching verbosity level.
void(*)(void *user_data) CloseHandlerCallbackT
Callback handle types.
void(*)(void *user_data, const Message &message) LogHandlerCallbackT
Callback handle types.
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 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 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)