FMPLog

Description

The FMPLog class is used to work with logs.

class FMPLog

Properties

Property Description

level

Logging level.
var level: FMPLog.Level { get set }
outputType Logging type.
var outputType: FMPLog.OutputType { get set }
isEnabled The checkbox that determines whether logging to console and database is enabled.
var isEnabled: Bool { get set }
isSecure The checkbox that determines whether secure data is hidden in logs.
var isSecure: Bool { get set }
database Logging database.
var database: FMPDatabase { get }

databaseLimit

The maximum number of log records in database. When the integer value greater than 0 is specified, the limit on the number of log records in database is set. When the specified limit is exceeded, the oldest records are deleted. To remove the limit, set the nil value or set the value less than or equal to 0.
var databaseLimit: Int32? { get set }

Methods

Method Description

debug(_:)

Write message to log. The information that is useful for the SDK user is written to database (statistics, basic settings, start/stop status, and so on). Logging level corresponds to the value of FMPLog.Level.debug. If the current logging level is greater, the message is not handled.
func debug(_ message: String)

Parameters:

  • message. Message text.

warning(_:) Write message to log. The warnings containing information that the user/developer should pay attention to application work result are written to database. Logging level corresponds to the value of FMPLog.Level.warning. If the current logging level is greater, the message is not handled.
func warning(_ message: String)

Parameters:

  • message. Message text.

error(_:) Write message to log. The error, after which an application can work but results may be unexpected, is written to database. Logging level corresponds to the value of FMPLog.Level.error. If the current logging level is greater, the message is not handled.
func error(_ message: String)

Parameters:

  • message. Message text.

getSchedule(completion:) Get schedule of sending logs to server.
func getSchedule(completion: @escaping FMPLogScheduleHandler)

Parameters:

  • completion. Closing expression containing method execution result.

sync(withClean:completion:) Synchronization of logs with server. It sends logs from mobile device to server.
func sync(withClean: Bool = true, completion: @escaping FMPRequestResponseHandler)

Parameters:

  • withClean. If the value is true, log records are deleted from local database after synchronization.

  • completion. Closing expression containing method execution result.

get(from:to:) Get logs from database for the specified period. It requests logs from database for the specified period. If the period limit(s) is(are) not specified, all records starting from the first and/or to the last one are returned. It returns the list of records from database for storing logs.
func get(from fromDate: Date? = nil, to toDate: Date? = nil) -> [FMPLog.Entry]

Parameters:

  • fromDate. Period start date and time.

  • toDate. Period end date and time.

clear(from:to:) Clear logs in database for the specified period. It deletes logs from database for the specified period. If the period limit(s) is(are) not specified, all records starting from the first and/or to the last one are deleted.
func clear(from fromDate: Date? = nil, to toDate: Date? = nil)

Parameters:

  • fromDate. Period start date and time.

  • toDate. Period end date and time.

getMeta() Get information about database with logs.
func getMeta() -> FMPLog.Meta?

Examples

Change logging level:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
// Change logging level
log.level = .verbose

Change logging type:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
// Change logging type
log.outputType = .database

Enable/disable logging:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
// Enable logging
log.isEnabled = true
// Disable logging
log.isEnabled = false

Enable/disable secure data logging:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
// Enable writing of secure data
log.isSecure = false
// Disable writing of secure data
log.isSecure = true

Set/remove limit on the number of log records in database:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
// Set the maximum number of log records
log.databaseLimit = 1000
  
// Remove limit on the number of records
log.databaseLimit = nil // option 1
log.databaseLimit = 0 // option 2
log.databaseLimit = -1 // option 3

Write custom logs:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
// Write debugging information
log.debug("debug")
  
// Write warning
log.warning("warning")
  
// Write error
log.error("error")

Get schedule of sending logs that is set on server:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
// Get schedule
log.getSchedule { (success, error, schedule) in
    if success {
        //  Display schedule
        print(schedule?.schedule)
    } else {
        // Display error code and description
        print(error?.code, error?.description)
    }
}

Send logs to server:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
// Send logs to server
log.sync { (response) in
    if response.success {
        //  Display server response
        print(response.result)
    } else {
        // Display error code and description
        print(response.error?.code, response.error?.description)
    }
}

Get logs from database for the specified period:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
let startDate: Date
let endDate: Date
 
// Get list of logs for the specified period
let logs: [FMPLog.Entry] = log.get(from: startDate, to: endDate)

Delete logs from database for the specified period:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
  
let startDate: Date
let endDate: Date
 
// Clear logs for the specified period
log.clear(from: startDate, to: endDate)

Get metainformation about database with logs:

// Build an instance of the FMPLog class. For details see examples for FMPLog.Builder.
let log: FMPLog = fmp.log.build()
 
// Get metainformation about database with logs
let meta: FMPLog.Meta? = log.getMeta()

See also:

FMPWrapper Framework | Classes