SAPcpmsLogUploader
public class SAPcpmsLogUploader
LogUploader can be used to upload persisted logs to SAPcpms. Applications which want to use the log upload feature must attach a handler to the Logger using ‘attachToRootLogger()’ method as soon as possible in the app’s lifecycle.
AppDelegate’s didFinishLaunchingWithOptions:
SAPcpmsLogUploader.attachToRootLogger()
Then, when you want to upload the logs:
SAPcpmsLogUploader.uploadLogs(sapURLSession: <#urlSession#>, settingsParameters: <#settingsParameters#>) { error in
// error handling
}
-
Boolean indicating if the upload of logs is enabled The configuration to upload the logs needs to be enabled in Mobile Services for the operation to be successful.
Declaration
Swift
public static var logUploadEnabled: Bool { get set }
-
Boolean indicating if the uploading the logs in chunks is enabled. The default value is ‘true’.
Declaration
Swift
public static var uploadLogInChunks: Bool { get set }
-
LogLevel of the LogUploadFileHandler; Use LogLevel.off to turn off logging for this handler If no LogUploadFileHandler exist the default value is ‘LogLevel.off’.
Declaration
Swift
public static var logLevel: LogLevel { get set }
-
Number of days after which the logfile will be deleted without uploading. 0 means there is no expiration.
Declaration
Swift
public static var logExpiration: Int
-
Default values for the maximum logfile size (
maxFileSize
)Declaration
Swift
public static var defaultMaxFileSize: UInt64
-
Default maximum number of backups before rolling over
Declaration
Swift
@available(*, deprecated, renamed: "defaultMaxFileNum") public static var defaultMaxBackups: Int
-
Maximum number of files before rolling over
Declaration
Swift
public static var defaultMaxFileNum: Int { get set }
-
Applies the SAPcpmsLogSettings parameters on SAPcpmsLogUploader and Logger
Declaration
Swift
public static func apply(sapcpmsLogSettings: SAPcpmsLogSettings)
Parameters
sapcpmsLogSettings
SAPcpmsLogSettings structure with entryExpiry, maxFileSize [MB], maxFileNum and logLevel properties
-
Attaches the LogUploader’s handler to the root logger. Make sure you call this method early in the lifecycle of your application to be sure that all log messages will be written into a file that later on can be uploaded using LogUploader.uploadLogs(urlSession:destinationURL:completionHandler)
Throws
LoggingError.LogFileCouldNotBeCreated(description: String)
if the base file is a directory and it exists.Declaration
Swift
public static func attachToRootLogger(maxFileSize: UInt64 = defaultMaxFileSize, maxFileNum: Int = defaultMaxFileNum) throws
Parameters
maxFileSize
the maximum size of a single log file in bytes. Cannot be negative. Passing
0
means that a file can grow unlimited in size. (Default 5MB)maxFileNum
the maximum number of logfiles that are stored on disk at the same time. Cannot be less than
1
. (Default 4) -
Attaches the LogUploader’s handler to the root logger. Make sure you call this method early in the lifecycle of your application to be sure that all log messages will be written into a file that later on can be uploaded using LogUploader.uploadLogs(urlSession:destinationURL:completionHandler)
Throws
LoggingError.LogFileCouldNotBeCreated(description: String)
if the base file is a directory and it exists.Declaration
Swift
@available(*, deprecated, renamed: "attachToRootLogger(maxFileSize:maxFileNum:﹚") public static func attachToRootLogger(maxFileSize: UInt64, maxBackups: Int) throws
Parameters
maxFileSize
the maximum size of a single log file in bytes. Cannot be negative. Passing
0
means that a file can grow unlimited in size. (Default 5MB)maxBackups
the maximum number of logfiles that are stored on disk at the same time. Cannot be less than
1
. (Default 4) -
Uploads persisted logs asynchronously @remark: uploaded logs are removed from persistence after a successful upload
Declaration
Swift
public static func uploadLogs(sapURLSession: SAPURLSession, settingsParameters: SAPcpmsSettingsParameters, completionHandler: @escaping (_ error: SAPcpmsLogUploaderError?) -> Void = SAPcpmsLogUploader.defaultCompletionHandler)
Parameters
session
a SAPURLSession implementation that can be used to communicate with the SAPcpms
settingsParameters
an instance of the SAPcpmsSettingsParameters with prefilled values to be able to concatenate the SAPcpms URL; Required parameters: host, applicationID
completionHandler
called after the request completes; The parameter is an Error that could be nil.
-
Uploads persisted logs asynchronously @remark: uploaded logs are removed from persistence after a successful upload
Declaration
Swift
public static func uploadLogs(sapURLSession: SAPURLSession, endpoint: URL, completionHandler: @escaping (_ error: SAPcpmsLogUploaderError?) -> Void = SAPcpmsLogUploader.defaultCompletionHandler)
Parameters
session
a SAPURLSession implementation that can be used to communicate with the SAPcpms
endpoint
full url where the logs will be uploaded
completionHandler
called after the request completes; The parameter is an Error that could be nil.
-
Deletes all log files without uploading it to the server. SAPcpmsLogUploader.attachToRootLogger() method must called before this method to attach the LogUploader’s handler to the root logger. This method uses the same queue as the uploadLogs() methods.
Throws
FileError.OperationFailed(NSError)
if one of the log files couldn’t be deleted.Declaration
Swift
public static func deleteLogFiles() throws
-
The default completion handler for SAPcpmsLogUploader.uploadLogs(). Logs the error with the root logger if there is any.
Declaration
Swift
public static func defaultCompletionHandler(error: Error?)
Parameters
error
error that will be logged