OSLogStore can't access an app's extensions?

I've got an iOS app with lots of extensions, some of them complex and doing a lot of stuff. After a bug I'd like to be able to use OSLogStore to get a holistic picture of logging for the app and its extensions and send that to a debugging server to retrospectively view logs for the app and its extensions.

The constructor is OSLogStore.init(scope: OSLogStore.Scope), however scope only has one value .currentProcessIdentifier.

Implying if that is called from within the app it can only get access to logging for its process only. I tried it out to confirm this is the case - if I log something in an extension (using Logger), then run the app with code like this:

 let logStore = try! OSLogStore(scope: .currentProcessIdentifier)
 let oneHourAgo = logStore.position(date: Date().addingTimeInterval(-3600))
 let allEntries = try! logStore.getEntries(at: oneHourAgo)
      for entry in allEntries {
            look at the content of the entry

Then none of the entries are from the extension.

Is there anyway from within the app I can access logging made within an extension?

Answered by DTS Engineer in 836392022

.currentProcessIdentifier means what it says: It gives you log entries for the current process. It doesn’t include log entries for any other process [1], and the fact that app extensions are related to the current process doesn’t change that.

On iOS and it’s child platforms, that’s the end of the story. On macOS, you have other ways to construct OSLogStore instances and those can be helpful.

For lots of info about the system log, see Your Friend the System Log.

As always, if you’d like to see things change in the future, I encourage you to file an enhancement request describing your requirements.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] It doesn’t even give you log entries for previously instances of the current program )-:

Please clarify "extensions" do you mean the extending of an already defined type or do you mean widgets, watch kit or some other Xcode app extension? If you're logging into a datastore on the disk you should not have a problem fetching from the entries but if you're using a logging level that just writes to memory then there is nothing to fetch. If the same data you're looking for is not visible in the mac console app when the phone is connected to the mac then that will also explain why the above code is not fetachable.

@MobileTen I mean an application extension, such as an action extension, notification content extension, notification service extension etc. I've rephrased the question to hopefully make it more understandable:

Is there a way of using Logger/OSLogStore such that logging performed within an extension can later be retrieved by the application? For example suppose an app is logging like this:

let logger = Logger(subsystem: "com.mysubsystem.log", category: "app") logger.debug("app stuff")

and suppose an extension (such as a notification service extension for example) logs like this:

let logger = Logger(subsystem: "com.mysubsystem.log", category: "ext") logger.debug("ext stuff")

Then next time the app runs, if it attempts to retrieves the log with code such as:

let logStore = try! OSLogStore(scope: .currentProcessIdentifier) let oneHourAgo = logStore.position(date: Date().addingTimeInterval(-3600)) let allEntries = try! logStore.getEntries(at: oneHourAgo) for entry in allEntries { look at the content of the entry

Then within the for loop, there's lots and lots of stuff retrieved, including "app stuff", but there is no "ext stuff". Is there anyway the application can retrospectively retrieve logging performed within the extension?

I have the same question (trying to fetch logs made by an app extension from the main app). Have you found a solution for this ?

.currentProcessIdentifier means what it says: It gives you log entries for the current process. It doesn’t include log entries for any other process [1], and the fact that app extensions are related to the current process doesn’t change that.

On iOS and it’s child platforms, that’s the end of the story. On macOS, you have other ways to construct OSLogStore instances and those can be helpful.

For lots of info about the system log, see Your Friend the System Log.

As always, if you’d like to see things change in the future, I encourage you to file an enhancement request describing your requirements.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] It doesn’t even give you log entries for previously instances of the current program )-:

OSLogStore can't access an app's extensions?
 
 
Q