Logging Guide

How to add logging across Android and iOS

Introduction

Logging is a basic need. This chapter describes how it is done on the different platforms.

iOS and OSX use the Apple Unified Logging System. Logs can be displayed using the OSX Console. See

Android logs are written into the Android Log System and displayed using LogCat. See here for an introduction

👍

Please find the Source code here

https://github.com/scadedoc/UgExamples/tree/master/UgLogging See Installing examples for information on how to download the examples.

Logging.swift helper class

We currently use a helper class for logging. Please copy this class into your project. Logging.swift at https://github.com/scadedoc/ScadeUtilities/blob/master/Sources/ScadeUtilities/Logging.swift

Getting started

To log, use the os_log function. To write message to the log, you use

os_log("my message info", type: .info)

You can use the default logging levels and all the logs you write show up on the different platforms:

  • for SCADE Simulator, log output shows in the SCADE IDE console and the OSX Console
  • for iOS Simulator, log output shows in the SCADE IDE console and the OSX Console
  • for iOS Devices, log output shows in the OSX Console
  • for Android Simulator, log output shows in the SCADE IDE console and Android logcat
  • for Android devices, log output shows in Android logcat
import ScadeKit

class MainPageAdapter: SCDLatticePageAdapter {

	// page adapter initialization
	override func load(_ path: String) {		
		super.load(path)
		
		os_log("my message info", type: .info)
		os_log("my message debug", type: .debug)
		os_log("my message error", type: .error)
		os_log("my message fault", type: .fault)
		
		log(.info,msg:"Hello info Log")
	}
	
}

SCADE Simulator

The SCADE Simulator writes the log into the OSX Console and the SCADE IDE console.

iOS Simulator

When running the app, you find the output in the OSX Console

Android logs

The log messages are written into the Android log. Each os_log invocation results into a logging message with the same logging level

OSLogTypeAndroid Log severity
.infoInformation
.debugDebug
.errorError
.faultFatal (not exposed in Java API)
.defaultInformation
not supportedVerbose
not supportedAssert

SCADE writes messages into logcat and outputs same messages into SCADE IDE console: