Updated on 2023-11-09 GMT+08:00

Log Analysis

Enabling System Logging

Sample code:

static OBSClient *client;
NSString *endPoint = @"your-endpoint";
// Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables AccessKeyID and SecretAccessKey.
// Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
char* ak_env = getenv("AccessKeyID");
char* sk_env = getenv("SecretAccessKey");
NSString *AK = [NSString stringWithUTF8String:ak_env];
NSString *SK = [NSString stringWithUTF8String:sk_env];
    
// Initialize identity authentication.
OBSStaticCredentialProvider *credentialProvider = [[OBSStaticCredentialProvider alloc] initWithAccessKey:AK secretKey:SK];
    
//Initialize service configuration.
OBSServiceConfiguration *conf = [[OBSServiceConfiguration alloc] initWithURLString:endPoint credentialProvider:credentialProvider];
    
// Initialize an instance of OBSClient.
client = [[OBSClient alloc] initWithConfiguration:conf];
    
// *****Logging settings*******
// Specify that system logs will be printed.
[client addLogger:[OBSDDASLLogger sharedInstance]];
// Specify that the logs will be displayed in the window.
[client addLogger:[OBSDDTTYLogger sharedInstance]];
    
// Set log files.
OBSDDFileLogger *fileLogger = [[OBSDDFileLogger alloc] init];
// Set the log retention duration.
fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling
// Set the maximum number of log files that can be retained.
fileLogger.logFileManager.maximumNumberOfLogFiles = 7;
    
// Customize log settings.
[client addLogger:fileLogger];
    
// Set the path for saving log files.
OBSDDLogFileInfo *ts =[fileLogger currentLogFileInfo];
NSLog(@"%@", ts);
    
// Set the log level.
[client setLogLevel:OBSDDLogLevelDebug];
    
// Enable logging.
[client setASLogOn];

Log Level

When current logs cannot be used to troubleshoot system faults, you can change the log level to obtain more information. You can obtain the most information in OBSDDLogLevelVerbose logs and the least information in OBSDDLogLevelError logs. The default value is OBSDDLogLevelInfo.

Log Level

Description

OBSDDLogLevelOff

Disables logging.

OBSDDLogLevelError

Prints error information only.

OBSDDLogLevelWarning

Prints error and alarm information.

OBSDDLogLevelInfo

Prints error, warning, and basic running information.

OBSDDLogLevelDebug

Prints error, warning, basic running, and debugging information.

OBSDDLogLevelVerbose

Prints all logs.