Log Initialization
API Description
You can enable the SDK log function to record log information generated during API calling into log files for subsequent data analysis or fault location. You can use InitLog to enable logging, CloseLog to disable logging, and SyncLog to synchronize log information from the cache to log files.
Initialization Method
func InitLog(logFullPath string, maxLogSize int64, backups int, level Level, logToConsole bool) error
Parameter Description
| Field | Type | Optional or Mandatory | Description |
|---|---|---|---|
| logFullPath | string | Mandatory | Full path to the log file |
| maxLogSize | int64 | Mandatory | Log file size in bytes |
| backups | int | Mandatory | Maximum number of log files that can be retained |
| level | Mandatory | Log level | |
| logToConsole | bool | Mandatory | Whether to print logs to the console |
Sample Code
// Import the dependency package. import ( "obs" ) func main() { // Set the path for saving log files. var logFullPath string = "./logs/OBS-SDK.log" // Set the size (in bytes) for each log file. var maxLogSize int64 = 1024 * 1024 * 10 // Set the number of retained log files. var backups int = 10 // Set the log level. var level = obs.LEVEL_INFO // Specify whether to print logs to the console. var logToConsole bool = false // Enable logging. obs.InitLog(logFullPath, maxLogSize, backups, level, logToConsole) // Disable logging and synchronize cache data to log files. obs.CloseLog() }
- The logging function is disabled by default. You need to enable it manually.
- For details about SDK logs, see Log Analysis.
- By default, logs are written to the cache (then written to log files after logs are accumulated to a certain amount). You can call obs.CloseLog() to forcibly synchronize the log information from the cache to log files.
Last Article: ObsClient Initialization
Next Article: SDK Custom Errors
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.