Skip to main content
Version: 7.0

PlanetKit initialization and log setting

You must initialize PlanetKit before using any functions of LINE Planet in your application. This page provides a code example for initializing PlanetKit and configuring log settings.

Initialization

Initialize PlanetKit using initialize() of PlanetKitManger with a PlanetKitInitialSettingBuilder object. You must set planet_base_url when calling initialize().

Note

You can find planet_base_url for each environment in Development environment.

class YourApplication {
func initializePlanetKit() {
let logDirectory = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!
.appendingPathComponent("PlanetKitLogs")
try! FileManager.default.createDirectory(at: logDirectory, withIntermediateDirectories: true)

let logOption = PlanetKitLogOption.withSizeLimit(
logDirectory: logDirectory.path,
logLevel: .simple,
logSizeLimit: .small
)

let settingBuilder = PlanetKitInitialSettingBuilder()
.withEnableLog(logOption: logOption!)
.withSetKitServerKey(serverUrl: planet_base_url)
let initialSettings = settingBuilder.build()
PlanetKitManager.shared.initialize(initialSettings: initialSettings)
...
}
}

Log setting

If you need to debug, you must configure logging using the withEnableLog(logOption:) method of the PlanetKitInitialSettingBuilder class during initialization. PlanetKit provides the PlanetKitLogOption class with methods for flexible log configuration.

Note
  • By default, the logging is disabled.
  • Starting with PlanetKit 5.1, logs can be output to files only.

Log levels

You can adjust the level of debug information output by setting the log level. Log level settings available in the PlanetKitLogLevel enum are as follows:

  • simple: PlanetKit outputs simple debug information.
  • detailed: PlanetKit outputs detailed debug information.
Note

To request debugging from the LINE Planet team, you must send a log file created with the detailed level.

Configure logging with size limit

To configure logging with automatic rotation when the size limit is reached, use the withSizeLimit(logDirectory:logLevel:logSizeLimit:) method.

  • Log file name
    • Log files are created according to internal logic, applying the rotation (for example, planetkit.log, planetkit.log.1, planetkit.log.2).
  • Log level
    • The default value of the logLevel parameter is simple.
  • Log size limit
    • Log size limit settings available in the PlanetKitLogSizeLimit enum are as follows:
      • small: The total size limit of log files is 16MB.
      • medium: The total size limit of log files is 64MB.
      • large: The total size limit of log files is 256MB.
    • The default value of the logSizeLimit parameter is large.

The following is an example of configuring logging with size limit.

let logDirectory = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!
.appendingPathComponent("PlanetKitLogs")
try! FileManager.default.createDirectory(at: logDirectory, withIntermediateDirectories: true)

let logOption = PlanetKitLogOption.withSizeLimit(
logDirectory: logDirectory.path,
logLevel: .simple,
logSizeLimit: .small
)

let settings = PlanetKitInitialSettingBuilder()
.withEnableLog(logOption: logOption!)
.withSetKitServerKey(serverUrl: planet_base_url)
.build()

PlanetKitManager.shared.initialize(initialSettings: settings)

Configure logging without size limit

To configure logging without a size limit, use the withSizeLimitUnlimited(logDirectory:logFileName:logLevel:) method.

  • Log file name
    • The default format of the log file created by the system is planetkitMMDD_HHMMSS.log, which includes a timestamp.
    • Optionally, you can set a custom file name in the logFileName parameter.
  • Log level
    • The default value of the logLevel parameter is simple.

The following is an example of configuring logging without size limit.

let logDirectory = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!
.appendingPathComponent("PlanetKitLogs")
try! FileManager.default.createDirectory(at: logDirectory, withIntermediateDirectories: true)

let logOption = PlanetKitLogOption.withSizeLimitUnlimited(
logDirectory: logDirectory.path,
logFileName: "myapp.log", // Optional: specify custom file name
logLevel: .detailed
)

let settings = PlanetKitInitialSettingBuilder()
.withEnableLog(logOption: logOption!)
.withSetKitServerKey(serverUrl: planet_base_url)
.build()

PlanetKitManager.shared.initialize(initialSettings: settings)