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