OSLog: anyway to get unified/combined logging from app and app extensions?

I've got a complex app extension and I'd like to be able to combine the logging from the app and the extension into a single file (for extraction/uploading etc.)

I experimented adding the following code to both the app and the extension i.e. using the same subsystem for both app and extension logging.

        let subsystem = "mySubsystem"
        let logger = Logger(subsystem: subsystem, category: "main")
        logger.info("Log from within extension") // the version in the app says Log from within app
        
         do {
            let logStore = try OSLogStore(scope: .currentProcessIdentifier)
            let oneHourAgo = logStore.position(date: Date().addingTimeInterval(-3600))
            let allEntries = try logStore.getEntries(at: oneHourAgo)
            let filtered = allEntries
                .compactMap { $0 as? OSLogEntryLog }
                .filter { $0.subsystem == subsystem }
        } 

The filtered content only contains logging from either the app or the extension.

I suppose the issue might be the use of .currentProcessIdentifier as the scope, however that's the only scope that is defined. Is what is being attempted here possible? Is there any way to write to and extract a unified log for an app and app extension? If not, how about adding it, surely this would be something useful for people to be able to do

Is what is being attempted here possible?

No. The .currentProcessIdentifier scope means literally the current process.

If not, how about adding it

I encourage you to file an enhancement request for the features that you need. Please post your bug number, just for the record.

Note that you can do this from Console, or any other logging UI, by using a predicate that matches the log entries from both your app and you app extension. I often do this by using the same subsystem for both and varying the category. However, there’s no way to achieve the same result programmatically.

Share and Enjoy

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

OSLog: anyway to get unified/combined logging from app and app extensions?
 
 
Q