Clarity is a logging framework that prints log data referenced from JSON to the console using semantic formatting.
Clarity assumes three main βnodesβ of interest in an application control flow: function call points, the resolution of conditional statements and the reporting of specific values including errors. Clarity print statements are designed to be placed at such node points in the client application code.
All message data relating to each print statement is placed entirely in associated JSON files referenced by a unique number. This enables the printing of an unlimited amount of information to the console with negligible impact on the source code.
The log output formatting is designed to emphasise nodes of interest in a clear narrative of the control flow instantly understandable by anyone β including non-developers. Settings enable the isolation of specific elements and referenced data.
Fully native and compatible with all Apple platforms, 100% stable, lightweight, and lightning fast β Clarity is a must-have framework for all Xcode projects.
π Complete granular control of all logs printed to the console:
π Deactivate printing for release without removing print statements:
π All print log data is separated from the source code:
π Public API with a negligible footprint to help maintain clean code:
π Print statement output designed to be easily read as a clear narrative of the control flow:
π Print statement output formatted using semantic assignment of symbols:
π Values and Errors can be passed as arguments to print statements:
π Custom or relative numbering system for tagging functions and control flow nodes.
π Number tag sequence only display:
π SwiftUI support:
body
vars and view modifiers.π Written entirely in Swift without third party dependancies.
π Easy to install and use:
π Comprehensive API docs website and reference documentation provided.
Use judiciously as a tool for logging print statements during project development or comprehensively at all node points to gain rapid understanding of an existing third party code base.
Note: the source and associated JSON extracts depicted above are for print statements in evaluateMyPet(_:) and changePet(_:) : the console also shows output from print statements in application(_:didFinishLaunchingWithOptions:) β see [example code](https://raw.github.com/real-intelligence/Clarity/main/iOS App Delegate Example) for full details.
ClarityJSON > Settings.json All other keys set to false
Key | Value |
---|---|
calculateFunctionNumbersRelativeToEntity | true |
calculateNodeNumbersRelativeToFunction | true |
displayNodePrintNumberWhenUsingRelativeNumbering | true |
ClarityJSON > Settings.json All other keys set to false
Key | Value |
---|---|
displayNodeSequenceWithoutDescriptions | true |
ClarityJSON > Settings.json All other keys set to false
Key | Value |
---|---|
suppressLogFunctionNames | true |
displayNodeSequenceWithoutDescriptions | true |
The different display options are controlled using a combination of keys in the Settings json file, the Formatting json file and keys within the associated EntityLogService json file.
See additional examples of using different node types and display options and the resulting console output in the documentation.
CS1 | CS2 | CS3 | CS4 | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Node type grouping: | ||||||||||||
Function name | Entity Code | Function βtypeβ symbol | Function number | Function name | ||||||||
Line 1: | ||||||||||||
Control flow / Reporters | Entity Code | Function number | Node βtypeβ symbol | Node number | Print number (relative setting) | Outcome/ Reporter/ Error symbol | Event description | |||||
Line 2: | ||||||||||||
Control flow | Event description | |||||||||||
Value Reporter | Value(s) list | |||||||||||
Error Reporter | Error description |
The 'CS' row marks the position of custom spacers (with a default value of 0).
Platforms | Minimum Swift Version | Installation | Status |
---|---|---|---|
iOS 14.5+, macOS 11.2+, tvOS 14.5+ , watchOS 7.4+ | 5 | Swift Package Manager, XCFramework, [Embedded Framework (using git submodules)](https://raw.github.com/real-intelligence/Clarity/main/#embedded framework) | Fully Tested |
https://github.com/real-intelligence/Clarity.git
Each release will include a clarity.xcframework
framework binary.
Navigate to latest release > https://github.com/real-intelligence/Clarity/releases
(select) Assets > Clarity.xcframework.zip
Doubleclick the downloaded zip file > move Clarity.xcframework to a convenient location.
Open > YourProjectNameβ¦
Project navigator > ProjectName > TARGET > ProjectName > General Tab...
Finder ... > select Clarity.xcframework > Drag and drop into the Frameworks, Libraries, and Embedded Content or Frameworks and Embedded Content of a client ProjectName if it is itself a framework.
Cmd+B to build the project.
Ensure that your project is initialized as a git repository.
Navigate to your project root folder > (right click) New Terminal at Folder
Add Clarity as a git submodule by running the following command:
$ git submodule add https://github.com/real-intelligence/Clarity.git
Your project root folder > Clarity > (Select) Clarity.xcodeproj Drag the icon into the Project Navigator of your application's Xcode project
It should appear nested underneath your application's blue project icon.
Project Navigator > Clarity.xcodeproj > PROJECT > Deployment Target ... Ensure the specific platform deployment target matches (or is less than) your application target
Project Navigator > Your project (xcodeproj) > TARGETS > General > Frameworks, Libraries, and Embedded Content
Click Add Items (plus icon)
(select) Clarity(relevant platform).framework
Add the Clarity activation initialiser at the entry point of the client application.
Important: The Clarity activation initialiser should only be called once in an application.
Note: if the displayStatus
parameter is omitted or set to true
βΒ the print mode and activation status of Clarity will be displayed at the top of the console output on initialisation.
Create a custom initialiser (if one does not already exist) for the type annotated with the @main
attribute that conforms to the App
protocol (the entry point of the application).
Add the Clarity import statement.
Note: Swift Package installations require import Clarity
for all platforms
XCFramework installations will require platform specific imports:
import Clarity
import Clarity_iOS
import Clarity_watch
import Clarity_tv
Add the Clarity activation initialiser.
import Clarity
@main
struct ClientForBigSuriOSApp: App {
init() {
ClarityActivator(withBundle: Bundle.main, inPrintMode: true, displayStatus:false)
...
}
Add activation to application(_:didFinishLaunchingWithOptions:)
import Clarity
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
ClarityActivator(withBundle: Bundle.main, inPrintMode: true, displayStatus:false)
...
}
Framework applications that have a single entry point or activation method should activate Clarity in the same way as shown above in the entry point method implementation.
Note: Framework applications will need to call the Bundle initialiser init(for:)
supplying the implementing class as argument to the aClass
parameter to access the correct Bundle for the framework.
Framework applications that do not have a single entry point will need to implement a class that includes a static variable that lazily stores the result of a closure containing the activation initialiser. The closure will then need to be accessed by all classes, structs or enums that use Clarity. This technique ensures that Clarity is activated only once and that any failure to activate Clarity will not adversely affect the client framework.
//Activation
import Clarity
class ClarityServiceExample {
static let clarityActivation: ClarityActivator? = {
return ClarityActivator(withBundle: Bundle(for: ClarityServiceExample.self), inPrintMode: true)
}()
}
//Accessing the activation
import Clarity
class MyClass {
public init() {
// All other essential initialisation work here β¦
guard let _ = ClarityService.clarityActivation else{
print("Clarity activation failed")
return
}
// Place a Clarity print statement for the initialiser here if required.
}
// Clarity print statements can now be placed anywhere in the class (struct or enum) as usual.
}
Run the client application in any Xcode device simulator.
A folder containing template and default settings JSON files named ClarityJSON will be copied to the desktop.
Note: running Clarity for the first time in a macOS application will likely cause a denied permissions issue when attempting to copy ClarityJSON to the desktop.
In this situation either temporarily switch the scheme to run once in a simulator or download the folder named TemplateJSON from the GitHub repository or locate the copy of the folder in the client project DerivedData, rename the folder to ClarityJSON and then continue to follow the instructions below (that are also given in the console).
All platforms except watchOS: Drag the folder named ClarityJSON from the desktop into: Xcode > Project Navigator > under (as a child of) the ProjectName icon.
watchOS only: Drag the folder named ClarityJSON from the desktop into: Xcode > Project Navigator > under (as a child of) the ProjectName Watchkit Extension folder.
In the pop up window:
All platforms except watchOS:
Xcode should place the directory at the top level of your project in the same directory containing the .xcodeproj file.
watchOS only:
Xcode should place the directory in the top level of the Watchkit Extension folder.
In all instances the folder should be coloured blue.
Copy and rename the EntityLog json template files for each entity (struct, class or enum) where Clarity print statements are required. Additional EntityLog json files can be added at any time.
Copy or move ExampleEntityLog.json to a separate location for reference and delete it from the ClarityJSON folder.
Note: Settings.json and Formatting.json must NOT be renamed, deleted or have their keys altered (the default values can be edited).
Add Clarity print statements to the project source code as required.
All reference materials can be found in the Documentation folder.
Full developer API docs can be found here.
Public API docs can be found here.
Clarity β created and maintained by Lawrence Heyfron.
If you like Clarity and want to support the project please let other developers know that the framework exists β tutorial creators are especially encouraged!
Feedback, code contributions, issues and pull requests including unit tests that add to the test coverage are welcomed. By making contributions to this project you give permission for your code to be used under the same license.
It would be great to know about projects using Clarity!
If you would like to support the maintenance of Clarity by making a donation any amount would be greatly appreciated.
If you use Clarity within an organisation or company ask if your employer might consider donating.
Copyright (c) 2021 Lawrence Heyfron https://realint.org/
Clarity is released under the MIT license. See LICENSE for details.
link |
Stars: 0 |
Last commit: 4 days ago |
First release β including XCFramework binary
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics