# Log Management

The Log management in the SDK is divided into two parts: console output and writing to log files. The APIs related to Log management are all called via [FATClient sharedClient].logManager.

# 1. Log Initialization Configuration

API

/// Initialize and enable log recording
/// @param logDir The storage path for log files. The default path is Sandbox Document/finclip_log (Do not place other files in this directory besides log files, as they may be cleaned up by the logging system)
/// @param logLevel The log recording level (FATLogLevelDebug is recommended for Debug builds, FATLogLevelInfo is recommended for Release builds)
/// @param isConsoleLog Whether to enable console output logging (Recommended to enable for Debug builds, disable for Release builds)
- (void)initLogWithLogDir:(NSString *)logDir logLevel:(FATLogLevel)logLevel consoleLog:(BOOL)isConsoleLog;

Sample code:

NSArray *patchs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [patchs objectAtIndex:0];
NSString *logDir = [documentsDirectory stringByAppendingPathComponent:@"ABC_FinClip_LogFiles"];

[[FATClient sharedClient].logManager initLogWithLogDir:logDir logLevel:FATLogLevelWarning consoleLog:YES];

# 2. Immediate Synchronization of Memory Logs to File

To avoid frequent file writes, log information exists in disk cache in MMAP form and is written to log files at appropriate times.

/// Immediately write logs in memory to the log file
/// Generally called when log files need to be exported, to update the latest logs to the log file.
/// If not called, these logs will not be lost; logs exist in disk cache in MMAP form and will be written to log files at appropriate times.
/// @param isAsync Whether to write asynchronously (Asynchronous is recommended, otherwise it may cause lag)
- (void)flushLog:(BOOL)isAsync;

# 3. Set Log File Retention Time

/// Set the log file retention time (Default is 10 days, minimum is 1 day)
/// @param duration Retention time, in seconds
- (void)setLogFileAliveDuration:(NSUInteger)duration;

# 4. Close Log

/// Close the log, called when the program exits (e.g., applicationWillTerminate:).
- (void)closeLog;

# 5. Log Output Delegate Events

The Host-App can implement the log output delegate to obtain logs or performance statistics data.

For the log delegate and sample code, see: logDelegate

© FinClip with ❤ , Since 2017