Log
This document mainly introduces the logging function of TuGraph.
1.Introduction
TuGraph keeps two types of logs: server logs and audit logs. Server logs record human-readable server status information, while audit logs maintain encrypted information for every operation performed on the server.
2.Server log
2.1.Server Log Categories
The server logs are currently divided into three categories: general log, debug log, and query log.
The general log is for regular users and includes important information related to the database startup and shutdown, such as configuration information during database startup, the port listened for services, and whether the database has successfully started or shut down. It provides a clear indication of whether the database is running.
The debug log is for database developers and includes debug-related information generated during runtime, such as network requests received by the database and the execution process of queries. It helps developers during development and developers can control the log level through the verbose configuration item.
(to be implemented)The query log is for business developers and includes information about each query executed by database and the performance-related information of the database when executing the query, such as query execution time. It can filter queries whose execution time is lower than the specified threshold time through configuration setting, making it easier for business developers to analyze performance.
2.2.Server Log Configuration Items
The output directory of server logs can be specified through the log_dir configuration item. The level of detail in the debug log can be specified through the verbose configuration item.
The log_dir configuration item is empty by default. If log_dir is empty, then all logs will be write to the console. If log_dir is manually specified, the following log folder structure will be generated in the corresponding path:
.
├── debug.log
├── general.log
├── query.log(TODO)
└── history_logs
├── debug_logs
├── general_logs
└── query_logs(TODO)
The general log is wrote into general.log file. The debug log is wrote into debug.log file. The query log is wrote into query.log file.
The maximum size of a single log file is 64mb, and when it reaches the maximum file size, it will be rotated into the history_logs folder. general.log is rotated into the general_logs folder, and debug.log is rotated into the debug_logs folder.
The verbose configuration item controls the level of detail of log records in debug log, and is divided into three levels of 0, 1, 2. Ther verbosity of log record grows as the number grows. The default level is 2, which records the most detailed log records. The server will print all log records in DEBUG level and above, and include the [filename:function:line_number] of the log records being printed, which is convenient for debugging. When the level is set to 1, the server will only print major events log records in INFO level and above. When the level is set to 0, the server will only print error log records in ERROR level and above.
2.3.Example of Server Log Output Macro Usage
If the developer wants to add logs to the code during development, they can refer to the following example:
#include "tools/lgraph_log.h" // add log dependency.
void LogExample() {
// The log module has been initialized during the database startup, and developers can directly call the macro.
// The log level is divided into six levels: TRACE, DEBUG, INFO, WARNING, ERROR, and FATAL.
GENERAL_LOG(INFO) << "This is a info level general log message."; // general log的输出宏
DEBUG_LOG(ERROR) << "This is a error level debug log message."; // debug log的输出宏
}
You can also refer to the log macro usage in test/test_lgraph_log.cpp.
3.Audit log
Audit logs record each request and response, as well as the user who sent the request and when the request received. Audit logging can only be turned on or off. The results can be queried using the TuGraph visualization tool and the REST API.