OSLogStore on watchOS

Hello.

I'm developing a tightly coupled watchOS/iOS app. The customer needs to be able to write logs to text files, from both apps, in a hassle-free way.

So I want to retrieve entries using OSLogStore, which works just fine on iOS:

let store = try OSLogStore(scope: .currentProcessIdentifier)
let pos = store.position(timeIntervalSinceEnd: -seconds)
let entries = try store
   .getEntries(with: [], at: pos, matching: nil)
   .compactMap { $0 as? OSLogEntryLog }
   .filter { $0.subsystem == Bundle.main.bundleIdentifier! }
   .map { "[\($0.date.formatted())] [\($0.category)] \($0.composedMessage)" }
   .joined(separator: "\n")

I've tried the same code on watchOS, with and without the filtering, but it always returns 0 entries.

I can't find anything relating to this behavior in the documentation. So... does it just not work?

Using a Watch SE 44mm and running watchOS 8.5

Thanks!

Answered by Frameworks Engineer in 723049022

Yes, logging is off by default on watchOS, and turning it on requires a logging profile to be installed.

I've found some posts saying I'd have to enable logging first by installing the sysdiagnose profile on Watch. Is that still the case? Ofc that would be pretty impractical for the end user and I'd have to look for a different solution.

Accepted Answer

Yes, logging is off by default on watchOS, and turning it on requires a logging profile to be installed.

OSLogStore on watchOS
 
 
Q