Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfLogger.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
25#ifndef _SOURCE_TFLOGGER_H_
26#define _SOURCE_TFLOGGER_H_
27
28#include <tf_port.h>
29#include <sstream>
30
31
32namespace TissueForge {
33
34
35 class CAPI_EXPORT LoggingBuffer
36 {
37 public:
38 LoggingBuffer(int level, const char* func, const char* file, int line);
39
44
48 std::ostream &stream();
49
50 private:
51 std::stringstream buffer;
52 int level;
53 const char* func;
54 const char* file;
55 int line;
56 };
57
70
71 enum LogEvent
72 {
73 LOG_OUTPUTSTREAM_CHANGED,
74 LOG_LEVEL_CHANGED,
75 LOG_CALLBACK_SET
76 };
77
78 typedef HRESULT (*LoggerCallback)(LogEvent, std::ostream *);
79
85 class CAPI_EXPORT Logger
86 {
87 public:
88
94 static void setLevel(int level = LOG_CURRENT);
95
101 static int getLevel();
102
106 static void disableLogging();
107
112
118 static void enableConsoleLogging(int level = LOG_CURRENT);
119
128 static void enableFileLogging(const std::string& fileName = "",
129 int level = LOG_CURRENT);
130
135 static void disableFileLogging();
136
142 static std::string getCurrentLevelAsString();
143
149 static std::string getFileName();
150
154 static std::string levelToString(int level);
155
159 static LogLevel stringToLevel(const std::string& str);
160
167 static void log(LogLevel level, const std::string& msg);
168
169
181 static void setConsoleStream(std::ostream *os);
182
183
184 static void setCallback(LoggerCallback);
185
186 };
187
188};
189
190#define TF_Log(level) \
191 if (level > TissueForge::Logger::getLevel()) { ; } \
192 else TissueForge::LoggingBuffer(level, TF_FUNCTION, __FILE__, __LINE__).stream()
193
194#endif // _SOURCE_TFLOGGER_H_
Definition tfLogger.h:86
static std::string getCurrentLevelAsString()
get the textural form of the current logging level.
static LogLevel stringToLevel(const std::string &str)
static void log(LogLevel level, const std::string &msg)
logs a message to the log.
static void setConsoleStream(std::ostream *os)
static std::string levelToString(int level)
static void setLevel(int level=LOG_CURRENT)
Set the Level objectsets the logging level to one a value from Logger::Level.
static int getLevel()
Get the Level objectget the current logging level.
static void disableFileLogging()
turns off file logging, but has no effect on console logging.
static void disableLogging()
Suppresses all logging output.
static void enableFileLogging(const std::string &fileName="", int level=LOG_CURRENT)
turns on file logging to the given file as the given level.
static void disableConsoleLogging()
stops logging to the console, but file logging may continue.
static void enableConsoleLogging(int level=LOG_CURRENT)
turns on console logging at the given level.
static std::string getFileName()
Get the File Name objectget the name of the currently used log file.
Definition tfLogger.h:36
std::ostream & stream()
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
LogLevel
Definition tfLogger.h:59
@ LOG_INFORMATION
An informational message, usually denoting the successful completion of an operation.
Definition tfLogger.h:66
@ LOG_CRITICAL
A critical error. The application might not be able to continue running successfully.
Definition tfLogger.h:62
@ LOG_DEBUG
A debugging message.
Definition tfLogger.h:67
@ LOG_FATAL
A fatal error. The application will most likely terminate. This is the highest priority.
Definition tfLogger.h:61
@ LOG_TRACE
A tracing message. This is the lowest priority.
Definition tfLogger.h:68
@ LOG_WARNING
A warning. An operation completed with an unexpected result.
Definition tfLogger.h:64
@ LOG_CURRENT
Use the current level – don't change the level from what it is.
Definition tfLogger.h:60
@ LOG_NOTICE
A notice, which is an information with just a higher priority.
Definition tfLogger.h:65
@ LOG_ERROR
An error. An operation did not complete successfully, but the application as a whole is not affected.
Definition tfLogger.h:63
int32_t HRESULT
Definition tf_port.h:255