投稿

10月, 2023の投稿を表示しています

【OSLog】How to log a Swift project

イメージ
Overview I found an article on the net that summarized how to use OSLog, I wanted a working sample. I am new to logging, so I wasn’t sure how to interpret the usage of OSLog. So I summarized it in my own way. What is OSLog? It is a library for logging that is provided by Apple and can be used in Swift projects. The official documentation is here . Sample https://github.com/Kuehar/OSLogSample When the above code is run, eight buttons are lined up as shown below. import SwiftUI import OSLog struct ContentView: View { let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ApplicationCode") var body: some View { VStack { Button(action: { logger.trace("Trace Log") }, label: { Text("Trace") }) Button(action: { logger.debug("Debug Log") }, label: { Text("Debug")