How to use OSLog in Xcode 12.5.1 or Xcode 13?

287 views Asked by At

I have tried using OSLog per documentation in both Xcode versions 12.5 and 13 with similar failure:

import SwiftUI
import CoreData
import OSLog

struct IdeaListView: View {
    let logger = Logger()
    let x = 42
    logger.info("The answer is \(x)

enter image description here

How is OSLog supposed to work? I don't see what I am doing wrong.

1

There are 1 answers

0
Shehata Gamal On

You should use this

Logger.info(.....

inside a function or a block not in struct level , e.x

struct ContentView: View {
    let logger = Logger()
    let x = 12
    var body: some View {
        Text("Hello, world!")
            .padding().onTapGesture {
                logger.info("This is a message \(x)")
            }
    }
}