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 Configuration Items
The output directory of server logs can be specified through the log_dir
configuration item. The level of log can be specified through the verbose
configuration item.
The log_dir
configuration item is empty by default. If log_dir
configuration item is empty, then all logs will be write to the console(nothing will be written to the console if the log_dir
configuration item is empty under daemon mode); if log_dir
configuration item is configured specifically, log files will bew generated under that path. The maximum size of a single log file is 256MB.
The verbose
configuration item controls the level of 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 1
. When the level is set to 2
, the server will print logs in DEBUG
level and above. When the level is set to 1
, the server will print logs in INFO
level and above. When the level is set to 0
, the server will print log in ERROR
level and above.
2.2.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 five levels: DEBUG, INFO, WARNING, ERROR, and FATAL.
LOG_DEBUG() << "This is a debug level log message.";
LOG_INFO() << "This is a info level log message.";
LOG_WARN() << "This is a warning level log message.";
LOG_ERROR() << "This is a error level log message.";
LOG_FATAL() << "This is a fatal level log message.";
}
You can also refer to the log macro usage in test/test_lgraph_log.cpp.
2.3.Procedure log
Developers can use the log function to output debug information that they need to the log for looking up and assisting development during the development of procedures. Debug information will be output to the same log file as the server log (if log_dir
configuration item is not specified, it will also be output to the console)
2.3.1.Cpp procedure
Please use the log macro provided in 2.2 to output debug information, and avoid using output methods such as cout or printf. For specific usage, please refer to the following sample code (see procedures/demo/log_demo.cpp
for details)
#include <stdlib.h>
#include "lgraph/lgraph.h"
#include "tools/lgraph_log.h" // add log dependency
using namespace lgraph_api;
void LogExample() {
LOG_DEBUG() << "This is a debug level log message.";
LOG_INFO() << "This is a info level log message.";
LOG_WARN() << "This is a warning level log message.";
LOG_ERROR() << "This is a error level log message.";
}
extern "C" bool Process(GraphDB& db, const std::string& request, std::string& response) {
response = "TuGraph log demo";
LogExample();
return true;
}
After inserting the above sample code into the database as a procedure and running it, you can see the corresponding log entries in the log file.
2.3.1.python procedure
Please use Python’s built-in print to output debug information. The debug information will be merged into a WARN-level log entry and output to the log file after the procedure is executed.
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.
To enable the Audit Log, you need to set the enable_audit_log
parameter to true
in the configuration file. For the configuration file and parameter descriptions, see:Tugraph Running/Service configuration