Level | Description | Scenarios |
VERBOSE | The most detailed debugging information, used for tracing the details of code execution flow. | Debugging during the development phase |
DEBUG | Debugging information for intermediate states of key processes. | Troubleshooting and process tracing |
INFO | General information, recording the results of key operations. | User behavior statistics, business monitoring |
WARN | Warning messages, indicating potential issues. | Abnormality monitoring and early warning |
ERROR | Error messages indicating feature failure. | Error analysis and repair |
Classification | Description |
PROCESS | Operation process log |
RESULT | Operation result log |
NETWORK | Network layer log |
PROBE | Network probe log (a probe is initiated when failure occurs due to network connection) |
ERROR | Error stack log |
Field | Field Key | Description | Type |
Timestamp. | timestamp | Precise to the millisecond | long |
Level | level | Log level | Enumeration |
Category | category | Log Classification | Enumeration |
Thread | threadName | Current thread name | String |
Tag APIs | tag | Custom Tags, used to distinguish business modules (such as Upload and Download) | String |
Message content | message | Log body information, supports formatted strings | String |
Device ID | deviceID | Device ID | String |
Model | deviceModel | Model | String |
APP version | appVersion | APP version | String |
Extended information | extras | Optional fields (such as device information and user information) Comes with qcloud_platform: Android, iOS, and so on Merged with deviceID, deviceModel, and appVersion during output | map<string, string> |
Time Tag Package name [Category][Thread] Message content - Extended fields map.
Level/Time [Thread] [Category Tag] [Message Content] [Extended Fields map].


// The enablement and disablement of console and file logging can be configured via the setDebuggable method in CosXmlServiceConfig. Logging is enabled when set to true.// whether to enable console loggingCOSLogger.enableLogcat(true);// whether to enable file loggingCOSLogger.enableLogFile(true);// Define a log listenerCosLogListener listener = new CosLogListener() {@Overridepublic void onLog(LogEntity entity) {Log.d("CosLogListener", entity.getLogcatString());}};// Add a log listenerCOSLogger.addLogListener(listener);// Remove a log listenerCOSLogger.removeLogListener(listener);// Set the global minimum log level (channel settings take precedence over global settings)COSLogger.setMinLevel(LogLevel.VERBOSE);// Set the minimum log level for console loggingCOSLogger.setLogcatMinLevel(LogLevel.VERBOSE);// Set the minimum log level for file loggingCOSLogger.setFileMinLevel(LogLevel.VERBOSE);// Set the minimum log level for cls (must be configured after setCLsChannel, otherwise it will not take effect)COSLogger.setClsMinLevel(LogLevel.VERBOSE);// Set Device IDCOSLogger.setDeviceID("DeviceID");// Set Device ModelCOSLogger.setDeviceModel("DeviceModel");// Set APP version numberCOSLogger.setAppVersion("AppVersion");// Set extension fieldMap<String, String> extras = new HashMap<>();extras.put("userID", "userID");COSLogger.setExtras(extras);// Obtain the log file list, with the parameter specifying the number of recent ones, e.g., the last 10 log filesFile[] files = COSLogger.getLogFiles(10);// Get the log file directory pathString logRootDir = COSLogger.getLogRootDir();// Add custom masking rulesCOSLogger.addSensitiveRule("(q-ak=)[^&\\\\\\\\s]+", "$1***");// Remove masking ruleCOSLogger.removeSensitiveRule("(q-ak=)[^&\\\\\\\\s]+");
// Set console log level[QCloudLogger sharedLogger].logLevel = QCloudLogLevelVerbose;// Set file log level[QCloudLogger sharedLogger].logFileLevel = QCloudLogLevelVerbose;// Set the minimum log level for cls (QCloudCLSLoggerOutput must be configured, otherwise it will not take effect)[QCloudLogger sharedLogger].logClsLevel = QCloudLogLevelVerbose;// Define a log listenerQCloudCustomLoggerOutput * output = [[QCloudCustomLoggerOutput alloc]init];output.callback = ^(QCloudLogModel * _Nonnull model, NSDictionary * _Nonnull extendInfo) {};// Add a log listener[[QCloudLogger sharedLogger] addLogger:output];// Remove a log listener[[QCloudLogger sharedLogger] removeLogger:output];// Set Device ID[QCloudLogger sharedLogger].deviceID = @"deviceID";// Set Device Model[QCloudLogger sharedLogger].deviceModel = @"deviceModel";// Set APP version number[QCloudLogger sharedLogger].appVersion = @"appVersion";// Set extension field[QCloudLogger sharedLogger].extendInfo = @{@"userID":@"userID"};// Get the log file directory pathNSString * logDir = [QCloudLogger sharedLogger].logDirctoryPath;
// whether to enable console loggingawait Cos().enableLogcat(true);// whether to enable file loggingawait Cos().enableLogFile(true);// Define a log listenerloglistener(log) {print(log.message);}// Add a log listenerawait Cos().addLogListener(loglistener);// Remove a log listenerawait Cos().removeLogListener(loglistener);// Set the global minimum log level (channel settings take precedence over global settings)await Cos().setMinLevel(LogLevel.verbose);// Set the minimum log level for console loggingawait Cos().setLogcatMinLevel(LogLevel.verbose);// Set the minimum log level for file loggingawait Cos().setFileMinLevel(LogLevel.verbose);// Set the minimum log level for cls (must be configured after setCLsChannel, otherwise it will not take effect)await Cos().setClsMinLevel(LogLevel.verbose);// Set Device IDawait Cos().setDeviceID("DeviceID");// Set Device Modelawait Cos().setDeviceModel("DeviceModel");// Set APP version numberawait Cos().setAppVersion("AppVersion");// Set extension fieldawait Cos().setExtras({"userId":"1"});// Get the log file directory pathString logRootDir = await Cos().getLogRootDir()
// whether to enable console loggingawait Cos.enableLogcat(true);// whether to enable file loggingawait Cos.enableLogFile(true);// Add a log listenerawait Cos.addLogListener("cos", (log) => {console.log(log);})// Remove a log listenerawait Cos.removeLogListener("cos");// Set the global minimum log level (channel settings take precedence over global settings)await Cos.setMinLevel(LogLevel.verbose);// Set the minimum log level for console loggingawait Cos.setLogcatMinLevel(LogLevel.verbose);// Set the minimum log level for file loggingawait Cos.setFileMinLevel(LogLevel.verbose);// Set the minimum log level for cls (must be configured after setCLsChannel, otherwise it will not take effect)await Cos.setClsMinLevel(LogLevel.verbose);// Set Device IDawait Cos.setDeviceID("DeviceID");// Set Device Modelawait Cos.setDeviceModel("DeviceModel");// Set APP version numberawait Cos.setAppVersion("AppVersion");// Set extension fieldawait Cos.setExtras({"userId":"1"});// Get the log file directory pathlet logRootDir = await Cos.getLogRootDir();
const cos = new COS({// Other configurations remain unchanged.// Local log relatedEnableLog: true, // Enable loggingEnableLogcat: true, // Output logs to the consoleLogLevel: 'VERBOSE', // Log levelLogExtras: { userId: '123' } // Additional log information});cos.on('log-message', msg => {// Log callbackconsole.log(msg);});
byte[] key = new byte[] {// 32-byte hexadecimal representation (example value; use secure random number generation in practice)0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};byte[] iv ={0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F};COSLogger.setLogFileEncryptionKey(key, iv);
// 32-byte hexadecimal representation (example value; use secure random number generation in practice)NSData *keyData = [NSData dataWithBytes:(unsigned char[]){0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F} length:32];NSData *ivData = [NSData dataWithBytes:(unsigned char[]){0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F} length:16];[QCloudLogger sharedLogger].aesKey = keyData;[QCloudLogger sharedLogger].aesIv = ivData;
// Create encryption keys and initialization vectorsfinal key = Uint8List.fromList([// 32-byte key (example value; use secure random number generation in practice)0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]);final iv = Uint8List.fromList([0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F]);// Call the method to set the log file encryption keyawait Cos().setLogFileEncryptionKey(key, iv);
// Create a 32-byte key and a 16-byte IV (example value; use secure random number generation in practice)const key = new Uint8Array([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]);const iv = new Uint8Array([0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F]);// Method for setting log file encryption keyawait Cos.setLogFileEncryptionKey(key, iv);
[4-byte length header][ciphertext data][4-byte length header][ciphertext data]....public class AesLogDecryptor {private static final String ALGORITHM = "AES/CBC/PKCS5Padding";public static void main(String[] args) {try {// The key and iv must be consistent with those configured during encryption.byte[] key = new byte[] {// 32-byte hexadecimal representation (example value; use secure random number generation in practice)0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};byte[] iv ={0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F};// Encrypted log file pathString encryptedFilePath = "2025-04-10-12-04-21_encrypt.log";// Output path of the decrypted log fileString decryptedFilePath = "2025-04-10-12-04-21_encrypt.log.decrypted";// Decrypt the filedecryptLogFile(new File(encryptedFilePath), new File(decryptedFilePath), key, iv);System.out.println("Decryption completed, result saved to: " + decryptedFilePath);} catch (Exception e) {System.err.println("Error occurred during decryption: " + e.getMessage());e.printStackTrace();}}/*** Decrypting encrypted log files* @param encryptedFile Encrypted log file* @param decryptedFile Decrypted output file* @param key AES key* @param iv Initialization vector* @throws Exception Exception that may be thrown during decryption*/public static void decryptLogFile(File encryptedFile, File decryptedFile, byte[] key, byte[] iv) throws Exception {System.err.print("iv: "+ Arrays.toString(iv));SecretKeySpec keySpec = new SecretKeySpec(key, "AES");IvParameterSpec ivSpec = new IvParameterSpec(iv);try (DataInputStream dis = new DataInputStream(new FileInputStream(encryptedFile));BufferedWriter writer = new BufferedWriter(new FileWriter(decryptedFile))) {while (dis.available() > 0) {// Read the 4-byte length header (big-endian)int length = dis.readInt();// Read ciphertext databyte[] encrypted = new byte[length];dis.readFully(encrypted);// Decrypt the dataString decrypted = new String(decryptSingle(encrypted, keySpec, ivSpec), StandardCharsets.UTF_8);// Write decrypted content to the output filewriter.write(decrypted);}}}/*** Decrypt a single data block* @param ciphertext Ciphertext data* @param keySpec Key specification* @param ivSpec Initialization vector specification* @return Decrypted byte array* @throws Exception Exception that may be thrown during decryption*/private static byte[] decryptSingle(byte[] ciphertext, SecretKeySpec keySpec, IvParameterSpec ivSpec) throws Exception {Cipher cipher = Cipher.getInstance(ALGORITHM);cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);return cipher.doFinal(ciphertext);}}
build.gradle:dependencies {...// Add these two linesimplementation 'com.tencentcloudapi.cls:tencentcloud-cls-sdk-android:1.0.5'implementation 'com.google.guava:guava:27.0.1-android'}
ClsLifecycleCredentialProvider subclass that implements the process of requesting temporary credentials and returning the result.ClsLifecycleCredentialProvider clsLifecycleCredentialProvider = new ClsLifecycleCredentialProvider() {@Overrideprotected ClsSessionCredentials fetchNewCredentials() throws ClsAuthenticationException {// First, obtain a response containing key information from your temporary key server// Then parse the response to obtain the temporary key informationString tmpSecretId = "SECRETID"; // Temporary key SecretIdString tmpSecretKey = "SECRETKEY"; // Temporary key SecretKeyString sessionToken = "SESSIONTOKEN"; // Temporary key Tokenlong expiredTime = 1556183496L; // Expiration timestamp of the temporary key in seconds// Finally, return the temporary key information objectreturn new ClsSessionCredentials(tmpSecretId, tmpSecretKey,sessionToken, expiredTime);}};
// CLS log topic ID and regionStringtopicId="c09216e3-ade5-4725-a000-000000000000";StringtopicEndpoint="ap-guangzhou.cls.tencentcs.com";// clsLifecycleCredentialProvider is the cls temporary key provider obtained in the previous step//Set up CLS channel (temporary key)COSLogger.setCLsChannel(topicId,topicEndpoint,clsLifecycleCredentialProvider);
// User's SecretId. It is recommended to use a sub-account key, with authorization following the principle of least privilege to reduce usage risks.// Sub-account key obtainment can be referred to https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1String secretId = "SECRETID";// User's SecretKey. It is recommended to use a sub-account key, with authorization following the principle of least privilege to reduce usage risks.// Sub-account key obtainment can be referred to https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1String secretKey = "SECRETKEY";// CLS log topic ID and regionStringtopicId="c09216e3-ade5-4725-a000-000000000000";StringtopicEndpoint="ap-guangzhou.cls.tencentcs.com";//Set up fixed key CLS channel (for testing only; not recommended to use fixed keys in production environments)COSLogger.setCLsChannel(topicId,topicEndpoint, secretId, secretKey);
<?xml version="1.0" encoding="utf-8"?><network-security-config><domain-config cleartextTrafficPermitted="true"><!--cls--><domain includeSubdomains="true">cls.tencentcs.com</domain></domain-config></network-security-config>
<application...android:networkSecurityConfig="@xml/network_security_config".../>
pod "QCloudTrack/Cls"
ClsLifecycleCredentialProvider subclass that implements the process of requesting temporary credentials and returning the result.QCloudCLSLoggerOutput * clsOutput = [[QCloudCLSLoggerOutput alloc]initWithTopicId:@"c09216e3-ade5-4725-a000-000000000000" endpoint:@"ap-guangzhou.cls.tencentcs.com"];[clsOutput setupCredentialsRefreshBlock:^QCloudCredential * _Nonnull{dispatch_semaphore_t semp = dispatch_semaphore_create(0);NSMutableURLRequest * mrequest = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@"Temporary key server address"]];__block QCloudCredential * credential = nil;// First, obtain the response containing key information from your temporary key server[[[NSURLSession sharedSession]dataTaskWithRequest:mrequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {if (data) {credential = [QCloudCredential new];NSDictionary * result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];NSDictionary * credentials = result[@"credentials"];credential.secretID = credentials[@"tmpSecretId"];credential.secretKey = credentials[@"tmpSecretKey"];credential.token = credentials[@"sessionToken"];credential.expirationDate = [NSDate dateWithTimeIntervalSinceNow:[credentials[@"sessionToken"] integerValue]];}dispatch_semaphore_signal(semp);}]resume];dispatch_semaphore_wait(semp, DISPATCH_TIME_FOREVER);return credential;}];[[QCloudLogger sharedLogger] addLogger:clsOutput];
// CLS log topic ID and regionStringtopicId="c09216e3-ade5-4725-a000-000000000000";StringtopicEndpoint="ap-guangzhou.cls.tencentcs.com";// clsLifecycleCredentialProvider is the cls temporary key provider obtained in the previous step//Set up CLS channel (temporary key)COSLogger.setCLsChannel(topicId,topicEndpoint,clsLifecycleCredentialProvider);
// User's SecretId. It is recommended to use a sub-account key, with authorization following the principle of least privilege to reduce usage risks.// Sub-account key obtainment can be referred to https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1NSString * secretId = @"SECRETID";// User's SecretKey. It is recommended to use a sub-account key, with authorization following the principle of least privilege to reduce usage risks.// Sub-account key obtainment can be referred to https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1NSString * secretKey = @"SECRETKEY";QCloudCLSLoggerOutput * clsOutput = [[QCloudCLSLoggerOutput alloc]initWithTopicId:@"c09216e3-ade5-4725-a000-000000000000" endpoint:@"ap-guangzhou.cls.tencentcs.com"];[clsOutput setupPermanentCredentialsSecretId:secretId secretKey:secretKey];[[QCloudLogger sharedLogger] addLogger:clsOutput];
build.gradle:dependencies {...// Add these two linesimplementation 'com.tencentcloudapi.cls:tencentcloud-cls-sdk-android:1.0.5'implementation 'com.google.guava:guava:27.0.1-android'}
pod "QCloudTrack/Cls"
class CLSFetchCLsChannelCredentials implements IFetchCLsChannelCredentials{@overrideFuture<SessionQCloudCredentials> fetchCLsChannelSessionCredentials() async {// First, obtain the response containing key information from your temporary key server// Then parse the response to obtain the temporary key informationString tmpSecretId = "SECRETID"; // Temporary key SecretIdString tmpSecretKey = "SECRETKEY"; // Temporary key SecretKeyString sessionToken = "SESSIONTOKEN"; // Temporary key Tokenlong expiredTime = 1556183496L; // Expiration timestamp of the temporary key, in seconds// Finally, return the temporary key information objectreturn SessionQCloudCredentials(secretId: tmpSecretId,secretKey: tmpSecretKey,token: sessionToken,expiredTime: expiredTime);}}
// CLS log topic ID and regionStringtopicId="c09216e3-ade5-4725-a000-000000000000";StringtopicEndpoint="ap-guangzhou.cls.tencentcs.com";//CLSFetchCLsChannelCredentialsis the cls temporary key provider obtained in the previous step//Set up CLS channel (temporary key)await Cos().setCLsChannelSessionCredential(topicId,topicEndpoint, CLSFetchCLsChannelCredentials());
// User's SecretId. It is recommended to use a sub-account key, with authorization following the principle of least privilege to reduce usage risks.// Sub-account key obtainment can be referred to https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1String secretId = "SECRETID";// User's SecretKey. It is recommended to use a sub-account key, with authorization following the principle of least privilege to reduce usage risks.// Sub-account key obtainment can be referred to https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1String secretKey = "SECRETKEY";// CLS log topic ID and regionStringtopicId="c09216e3-ade5-4725-a000-000000000000";StringtopicEndpoint="ap-guangzhou.cls.tencentcs.com";//Set up fixed key CLS channel (for testing only; not recommended to use fixed keys in production environments)await Cos().setCLsChannelStaticKey(topicId,topicEndpoint, secretId, secretKey);
<?xml version="1.0" encoding="utf-8"?><network-security-config><domain-config cleartextTrafficPermitted="true"><!--cls--><domain includeSubdomains="true">cls.tencentcs.com</domain></domain-config></network-security-config>
<application...android:networkSecurityConfig="@xml/network_security_config".../>
build.gradle:dependencies {...// Add these two linesimplementation 'com.tencentcloudapi.cls:tencentcloud-cls-sdk-android:1.0.5'implementation 'com.google.guava:guava:27.0.1-android'}
pod "QCloudTrack/Cls"
// CLS log topic ID and regionlettopicId="c09216e3-ade5-4725-a000-000000000000";lettopicEndpoint="ap-guangzhou.cls.tencentcs.com";//Set up CLS channel (temporary key)Cos.setCLsChannelSessionCredential(topicId,topicEndpoint, async () => {// First, obtain the response containing key information from your temporary key server// Then parse the response to obtain the temporary key informationlet tmpSecretId = "SECRETID"; // Temporary key SecretIdlet tmpSecretKey = "SECRETKEY"; // Temporary key SecretKeylet sessionToken = "SESSIONTOKEN"; // Temporary key Tokenlet expiredTime = 1556183496L; // Expiration timestamp of the temporary key, in seconds// Finally, return the temporary key information objectconst sessionCredentials = {tmpSecretId: tmpSecretId,tmpSecretKey: tmpSecretKey,expiredTime: expiredTime,sessionToken: sessionToken};return sessionCredentials;});
// User's SecretId. It is recommended to use a sub-account key, with authorization following the principle of least privilege to reduce usage risks.// Sub-account key obtainment can be referred to https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1let secretId = "SECRETID";// User's SecretKey. It is recommended to use a sub-account key, with authorization following the principle of least privilege to reduce usage risks.// Sub-account key obtainment can be referred to https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1let secretKey = "SECRETKEY";// CLS log topic ID and regionlettopicId="c09216e3-ade5-4725-a000-000000000000";lettopicEndpoint="ap-guangzhou.cls.tencentcs.com";//Set up fixed key CLS channel (for testing only; not recommended to use fixed keys in production environments)await Cos.setCLsChannelStaticKey(topicId,topicEndpoint, secretId, secretKey)
<?xml version="1.0" encoding="utf-8"?><network-security-config><domain-config cleartextTrafficPermitted="true"><!--cls--><domain includeSubdomains="true">cls.tencentcs.com</domain></domain-config></network-security-config>
<application...android:networkSecurityConfig="@xml/network_security_config".../>
const ClsClient = require('demo/common/cls.min.js');
const clsClient = new ClsClient({topicId: 'c09216e3-ade5-4725-a000-000000000000', // log topic idregion: 'ap-guangzhou', // region of the log topic, such as ap-guangzhoumaxRetainDuration: 30, // Default 30smaxRetainSize: 20, // Default 20 entries});const cos = new COS({ClsLogger: clsClient, // Output logs to cls});
Feedback