#include <utils.hpp>
- Examples
- linreg.cpp.
Definition at line 96 of file utils.hpp.
◆ Logger()
gpmp::core::Logger::Logger |
( |
LogLevel |
level = INFO , |
|
|
bool |
useTimestamp = true |
|
) |
| |
Constructs a Logger instance.
- Parameters
-
level | The minimum log level to record |
useTimestamp | Whether to include timestamps in log messages (default: true) |
destination | The log destination, which can be CONSOLE, FILE_ONLY, or CONSOLE_AND_FILE (default: CONSOLE) |
logFile | The name of the log file (if destination is FILE_ONLY or CONSOLE_AND_FILE) |
Definition at line 46 of file utils.cpp.
LogLevel logLevel
The minimum log level to record.
LogDestination logDestination
The log destination, which can be CONSOLE, FILE_ONLY, or CONSOLE_AND_FILE.
bool logToFile
Flag indicating whether to log messages to a file.
bool enableTimestamp
Flag indicating whether to include timestamps in log messages.
◆ ~Logger()
gpmp::core::Logger::~Logger |
( |
| ) |
|
Logger destructor, destroys the Logger instance.
Definition at line 51 of file utils.cpp.
std::ofstream logFileStream
The output stream for logging to a file.
◆ enableTimestamps()
void gpmp::core::Logger::enableTimestamps |
( |
bool |
enable | ) |
|
Enables or disables timestamps in log messages.
- Parameters
-
enable | True to enable timestamps, false to disable |
Definition at line 61 of file utils.cpp.
◆ formatLogMessage()
std::string gpmp::core::Logger::formatLogMessage |
( |
const std::string & |
prefix, |
|
|
const std::string & |
message |
|
) |
| |
|
private |
Formats a log message with a specified prefix.
- Parameters
-
prefix | The log message prefix |
message | The log message content |
- Returns
- The formatted log message as a string
Definition at line 125 of file utils.cpp.
127 std::string logMessage = prefix +
" " + message;
std::string getCurrentTimestamp()
Gets the current timestamp as a string.
◆ getCurrentTimestamp()
std::string gpmp::core::Logger::getCurrentTimestamp |
( |
| ) |
|
|
private |
Gets the current timestamp as a string.
- Returns
- A string representing the current timestamp
Definition at line 110 of file utils.cpp.
111 auto now = std::chrono::system_clock::now();
112 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
113 now.time_since_epoch()) %
115 std::time_t nowTime = std::chrono::system_clock::to_time_t(now);
116 std::tm tm = *std::localtime(&nowTime);
118 std::ostringstream oss;
119 oss << std::put_time(&tm,
"%H:%M:%S") <<
'.' << std::setfill(
'0')
120 << std::setw(3) << ms.count();
◆ getLogPrefix()
std::string gpmp::core::Logger::getLogPrefix |
( |
LogLevel |
level | ) |
|
|
private |
Gets the log prefix based on the log level.
- Parameters
-
- Returns
- A string representing the log prefix
Definition at line 95 of file utils.cpp.
References DEBUG, ERROR, INFO, and WARNING.
◆ log()
void gpmp::core::Logger::log |
( |
LogLevel |
level, |
|
|
const std::string & |
message |
|
) |
| |
Logs a message with the specified log level.
- Parameters
-
level | The log level of the message |
message | The message to log |
- Examples
- linreg.cpp.
Definition at line 77 of file utils.cpp.
84 std::cerr << logMessage << std::endl;
86 std::cout << logMessage << std::endl;
std::string formatLogMessage(const std::string &prefix, const std::string &message)
Formats a log message with a specified prefix.
std::string getLogPrefix(LogLevel level)
Gets the log prefix based on the log level.
References CONSOLE, CONSOLE_AND_FILE, and ERROR.
Referenced by gpmp::ml::LinearRegression::best_fit(), gpmp::core::DataTable::datetime(), gpmp::ml::LinearRegression::get_input(), gpmp::core::DataTable::group_by(), gpmp::core::DataTable::inferType(), gpmp::core::DataTable::native_type(), gpmp::ml::LinearRegression::r_sqrd(), gpmp::ml::LinearRegression::split_data(), and test_train().
◆ setLogDestination()
void gpmp::core::Logger::setLogDestination |
( |
LogDestination |
destination | ) |
|
Sets the log destination.
- Parameters
-
destination | The log destination, which can be CONSOLE, FILE_ONLY, or CONSOLE_AND_FILE |
Definition at line 65 of file utils.cpp.
◆ setLogFile()
void gpmp::core::Logger::setLogFile |
( |
const std::string & |
logFile | ) |
|
Sets the log file name for FILE_ONLY or CONSOLE_AND_FILE destinations.
- Parameters
-
logFile | The name of the log file |
Definition at line 69 of file utils.cpp.
73 std::cerr <<
"Error: Could not open log file " << logFile << std::endl;
◆ setLogLevel()
void gpmp::core::Logger::setLogLevel |
( |
LogLevel |
level | ) |
|
Sets the minimum log level.
- Parameters
-
level | The minimum log level to record |
Definition at line 57 of file utils.cpp.
◆ enableTimestamp
bool gpmp::core::Logger::enableTimestamp |
|
private |
Flag indicating whether to include timestamps in log messages.
Definition at line 157 of file utils.hpp.
◆ logDestination
The log destination, which can be CONSOLE, FILE_ONLY, or CONSOLE_AND_FILE.
Definition at line 163 of file utils.hpp.
◆ logFileStream
std::ofstream gpmp::core::Logger::logFileStream |
|
private |
The output stream for logging to a file.
Definition at line 173 of file utils.hpp.
◆ logLevel
The minimum log level to record.
Definition at line 152 of file utils.hpp.
◆ logToFile
bool gpmp::core::Logger::logToFile |
|
private |
Flag indicating whether to log messages to a file.
Definition at line 168 of file utils.hpp.
The documentation for this class was generated from the following files: