Log Configuration
This document is used to carry the HarmonyOS Log initialization configuration.
Initialization Configuration
import { FTSDK, FTLoggerConfig, Status } from '@guancecloud/ft_sdk/Index';
const logGlobalContext = new Map<string, string | number | boolean | object>();
logGlobalContext.set('demo_log_number_tag', 101);
const logConfig = new FTLoggerConfig()
.setSamplingRate(1.0)
.setEnableCustomLog(true)
.setLogLevelFilters([
Status.ERROR,
Status.WARN,
Status.INFO,
Status.DEBUG
])
.setEnableLinkRumData(true)
.addGlobalContext(logGlobalContext)
.setLogCacheLimitCount(10000);
FTSDK.installLogConfig(logConfig);
| Method |
Type |
Required |
Description |
setSamplingRate |
number |
No |
Log sampling rate, range [0.0, 1.0], default 1.0 |
setEnableCustomLog |
boolean |
No |
Whether to enable custom logs, default false |
setEnableLinkRumData |
boolean |
No |
Whether to associate RUM data, default false |
setLogLevelFilters |
Array<Status | string | { name: string }> |
No |
Log level filtering, optional values: ERROR, WARN, INFO, DEBUG |
addGlobalContext |
Dictionary |
No |
Add log global attributes. For addition rules, please refer to here |
setLogCacheLimitCount |
number |
No |
Log data cache limit count, default 5000, minimum 1000 |
setLogCacheDiscardStrategy |
LogCacheDiscard |
No |
Set the log discard rule when the limit is reached, default is LogCacheDiscard.DISCARD. DISCARD discards appended data, DISCARD_OLDEST discards oldest data |
Log Levels
| Method Name |
Meaning |
| Status.TRACE |
Trace |
| Status.DEBUG |
Debug |
| Status.INFO |
Info |
| Status.WARN |
Warn |
| Status.ERROR |
Error |
| Status.FATAL |
Fatal |
Dynamically Append Log Global Attributes
import { FTSDK } from '@guancecloud/ft_sdk/Index'
const dynamicContext = new Map<string, string | number | boolean | object>();
dynamicContext.set('user_level', 'vip')
FTSDK.appendLogGlobalContext(dynamicContext)
FTSDK.appendLogGlobalContextKeyValue('login_state', 'logged_in')
Usage Recommendations
- During debugging, you can combine
setEnableCustomLog(true) with SDK Debug logs to verify the collection pipeline.
- If you want logs to be correlated with user behavior, page, and resource data for analysis, it is recommended to also enable
setEnableLinkRumData(true).
- If the log volume is large, you can control the upload volume through sampling rate and level filtering.