Post not yet marked as solved
In my sandboxed MacOS app I want to access OSLogStore programmatically to fetch logs for multi-component application (app, libraries, deriver) for further analysis. According to the documentation, - https://developer.apple.com/documentation/oslog/oslogstore/3366102-local the app should have com.apple.logging.local-storeentitlement.
I have added this entitlement "by hand" to the entitlement file as I I can't find a correspondent entry in the Xcode -> Sign & Capabilities interface.
When I run the app, I get Unsatisfied entitlements: com.apple.logging.local-store error and the app doesn't start.
If I remove the entitlement, the app can't get access to the logd subsystem.
How can I add com.apple.logging.local-store to my app?
Should I request this not visible via Xcode configuration UI from apple?
Thanks!
Post not yet marked as solved
I have read several times
https://developer.apple.com/forums/thread/705868
https://developer.apple.com/forums/thread/705810
https://developer.apple.com/documentation/os/logging/generating_log_messages_from_your_code#3665948
From what I understand code like this:
import SwiftUI
import OSLog
struct ContentView: View {
private static let logger = Logger(subsystem: "HCP", category: "ContentView")
var myprivateData: Date { Date() }
var myprivateData2: String { "bank-account-111-222-333" }
let myprivateData3: String = "bank-account-111-222-333"
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
.onAppear(perform: {
Self.logger.info("test info")
Self.logger.info("test info \(myprivateData)")
Self.logger.info("test info \(myprivateData2)")
Self.logger.info("test info \(myprivateData3)")
Self.logger.info("test info")
Self.logger.info("test info \(myprivateData, privacy: .private)")
Self.logger.info("test info \(myprivateData2, privacy: .private)")
Self.logger.info("test info \(myprivateData3, privacy: .private)")
})
}
}
Should result in somewhat redacted log messages, so my expectation would be that dynamic strings
Self.logger.info("test info1")
Self.logger.info("test info2 \(myprivateData)")
Self.logger.info("test info3 \(myprivateData2)")
Self.logger.info("test info4 \(myprivateData3)")
would result in logs like:
info 21:29:07.877698+0200 TestOsLogger test info1
info 21:29:07.877757+0200 TestOsLogger test info2 <private>
info 21:29:07.877800+0200 TestOsLogger test info3 <private>
info 21:29:07.877835+0200 TestOsLogger test info4 <private>
instead I get
info 21:29:07.874356+0200 TestOsLogger test info1
info 21:29:07.877531+0200 TestOsLogger test info2 <private>
info 21:29:07.877615+0200 TestOsLogger test info3 bank-account-111-222-333
info 21:29:07.877656+0200 TestOsLogger test info4 bank-account-111-222-333
where clearly date object got redacted, but string not really.
Adding privacy: .private helps here, but it is still a different behavior from what I expected after reading docs.
Is that a change or rather my misunderstanding? Eskimo for the rescue?
Post not yet marked as solved
Since MacOS 14.4 I've been having trouble seeing logs emitted from my applications with oslog. For example:
#import <Foundation/Foundation.h>
#include <os/log.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
os_log_error(OS_LOG_DEFAULT, "Hello World!");
}
return 0;
}
When I compile and run this in Xcode I do see the log message in Xcode itself. But I'm not able to see anything with log stream --source --predicate "eventMessage contains 'Hello'" or the Console.app if I run the same program in Xcode or outside. I do see logs from other applications on the same machine so it's not completely down.
Any suggestions on how to debug this? Perhaps something missing in the project that would "enable" logging?
Post not yet marked as solved
Hi.
I want to use OSLog. It is working as expected inside my controller. I can view all details in the console and can use "jump to source" and it jumps to the source code :) NICE
If I call this inside a package in side a static func like this
Package Example:
import OSLog
class A {
static func testLog(meesage: String) {
Logger(subsystem: "Test", category: "console").info("\(message)")
}
}
I can the message inside the console but "Jump to soure" is not working. Only a ?
appears on screen.
Did I miss anything ?
Post not yet marked as solved
I have os_log statements in my app. With my phone connected to the Mac, when I run the app through XCode, open Console app, those logs are shown. However, when I'm launching the app on its own, those logs don't appear in Console (phone still connected).
Am I missing something very basic? Please help.
I have an iOS app that uses os_signpost API for instrumentation.
When I profile it from Xcode on real iOS device, it works as expected.
When I profile its macCatalyst variant (using the identical code) on the same Mac where Xcode is running, the os_signpost Instrument does not show anything, not even the Apple provided signposts that are otherwise visible on the iOS.
How do I make it work?
Post not yet marked as solved
My requirement is here-
1- We need to implement functionality in my iOS app to do call (cellular call) without user interaction.
2- We need to implement functionality in my iOS app to send normal message to particular phone number without user interaction.
3- Fetch OS log (NOT MY APPLICATION LOG). we need to fetch OS log when cellular call going on in device this log need to collect in my iOS app for identify the network strength and other things like call is connected and disconnect etc. Thanks
Post not yet marked as solved
If I create a new project with the following code in main.swift and then Profile it in Instruments with the CPU Profiler template, nothing is logged in the Points of Interest category. I'm not sure if this is related to the recent macOS 14.2 update, but I'm running Xcode 15.1.
import Foundation
import OSLog
let signposter = OSSignposter(subsystem: "hofstee.test", category: .pointsOfInterest)
// os_signpost event #1
signposter.emitEvent("foo")
// os_signpost event #2
signposter.withIntervalSignpost("bar") {
print("Hello, World!")
}
If I change the template to the System Trace template and profile again, then the two os_signpost events show up as expected.
This used to work before, and this is a completely clean Xcode project created from the macOS Command Line Tool template. I'm not sure what's going on and searching for answers hasn't been fruitful. Changing the Bundle ID doesn't have any effect either.
The new Xcode 15.3 Release Candidate produces errors with strict concurrency checking that the usual pattern of using OSLog with a static property like static let logger = Logger(...) is not safe.
"Static property 'logger' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6"
Is Logger thread safe and just not marked Sendable? Would it be "safe" to use nonisolated(unsafe) static let logger = Logger(...)?
Post not yet marked as solved
I am using sudo log collect --device-udid {device-udid} --last 7m command to collect console.app logs .
But it seems only info and error logs are getting collected in logarchive file even though I can se debug level logs getting printed in console.app .
How we can change the level to collect debug level logs as well from console app.
Options log collect command have -:
--device Collect logs from first device found
--device-name Collect logs from device with the given name
--device-udid Collect logs from device with the given UDID
--last [m|h|d] Collect logs starting [m|h|d] ago
-output Output log archive to the given path
--size [k|m] Limit log collection to the given size
--start Collect logs starting at the given time
There is no way to provide debug level in command .
Post not yet marked as solved
I've encountered an issue while reviewing logs from my device and hope someone here can shed some light on it. In the process of diagnosing an application behavior, I noticed that some entries in my logs are marked as , specifically next to bundle IDs, which makes it challenging to understand which app or process is involved.
Here are the relevant log entries:
Feb 21 17:40:53 vCw-2 suggestd(CoreSuggestionsInternals)[30399] <Notice>: SGDSuggestManager: realtimeSuggestionsForMailOrMessageWithHash: com.apple.MobileSMS : <private>
Feb 21 17:40:53 vCw-2 suggestd(CoreSuggestionsInternals)[30399] <Notice>: SGDSuggestManager: realtimeSuggestionsForMailOrMessageWithHash: <private>: results: (null)
Feb 21 17:40:53 vCw-2 suggestd(CoreSuggestionsInternals)[30399] <Notice>: SGDSuggestManager: realtimeSuggestionsForMailOrMessageWithHash: com.apple.MobileSMS : <private>
Feb 21 17:40:53 vCw-2 suggestd(CoreSuggestionsInternals)[30399] <Notice>: SGDSuggestManager: starting dissection.
The identification of this hidden bundle ID is essential for allowing the specific iMessage Business Chat feature to function as intended in our MDM-managed devices.
Does anyone have insights into why the bundle ID might be hidden or how to uncover it? Are there tools or methods available that could help me identify this bundle ID for MDM whitelist configuration purposes?
I appreciate any guidance or recommendations you can provide. Thank you for your time and assistance.
Post not yet marked as solved
Background
I have a SwiftUI app that uses OSLog and the new Logger framework. In my SwiftUI views, I would like to use something like Self._logChanges() to help debug issues.
After some trial and error, I can see the messages appear in the System console log for the app I am debugging using the com.apple.SwiftUI subsystem.
Problem
I'd like to see those same messages directly in Xcode's console window so I can filter them as needed. How do I do that?
Thanks! -Patrick
We use OSLog to log message in our iOS app and retrieve logs to save into local file when app goes to background. This way we will be able to persist logs after app terminated. However, when logs become large, retrieving logs takes more than 5 seconds during background transition that cause our app being killed by the system with below info:
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: FRONTBOARD 2343432205
<RBSTerminateContext| domain:10 code:0x8BADF00D explanation:scene-update watchdog transgression: app<com.cisco.secureclient.zta(B7AB7300-8A17-4C71-88BC-BA3D55AF6666)>:1261 exhausted real (wall clock) time allowance of 10.00 seconds
ProcessVisibility: Background
ProcessState: Running
WatchdogEvent: scene-update
WatchdogVisibility: Background
WatchdogCPUStatistics: (
"Elapsed total CPU time (seconds): 13.500 (user 10.890, system 2.610), 21% CPU",
"Elapsed application CPU time (seconds): 2.119, 3% CPU"
) reportType:CrashLog maxTerminationResistance:Interactive>
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x1ed6e01d8 mach_msg2_trap + 8
1 libsystem_kernel.dylib 0x1ed6dff70 mach_msg2_internal + 80
2 libsystem_kernel.dylib 0x1ed6dfe88 mach_msg_overwrite + 436
3 libsystem_kernel.dylib 0x1ed6dfcc8 mach_msg + 24
4 libdispatch.dylib 0x1aea4df00 _dispatch_mach_send_and_wait_for_reply + 540
5 libdispatch.dylib 0x1aea4e2a0 dispatch_mach_send_with_result_and_wait_for_reply + 60
6 libxpc.dylib 0x20fd406d0 xpc_connection_send_message_with_reply_sync + 264
7 Foundation 0x1a5ad96c0 NSXPCCONNECTION_IS_WAITING_FOR_A_SYNCHRONOUS_REPLY + 16
8 Foundation 0x1a5ac13bc -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 2160
9 Foundation 0x1a5aec6cc -[NSXPCConnection _sendSelector:withProxy:arg1:] + 116
10 Foundation 0x1a5aec604 _NSXPCDistantObjectSimpleMessageSend1 + 60
11 OSLog 0x1f4b98118 -[OSLogCurrentProcessEnumerator nextObject] + 192
12 libswiftOSLog.dylib 0x213983270 OSLogStore.PrivateIterator.next() + 32
13 libswiftOSLog.dylib 0x213983324 protocol witness for IteratorProtocol.next() in conformance OSLogStore.PrivateIterator + 28
14 libswiftCore.dylib 0x1a0050ed0 _IteratorBox.next() + 108
15 MyApp 0x104359e28 static MyLogger.getFormattedLogs() (in MyApp ) (MyLogger.swift:63) + 122408
Here is our code to retrieve logs:
struct MyLogger {
public var log: Logger
init(subsystem: String = getSubsystem(),
file: String = #file,
function: String = #function,
line: Int = #line,
context: String = "myapp")
{
let category = "\(context): \(file): \(line): \(function): "
log = Logger(subsystem: subsystem, category: category)
}
static func getFormattedLogs() -> [String]
{
do {
// Combine log message with timestamp and category with
// file/line/function information
let df = DateFormatter()
df.dateFormat = ZtaConstants.DATE_FORMAT
let store = try OSLogStore.init(scope: .currentProcessIdentifier)
let logEntries = try store.getEntries()
.compactMap{ $0 as? OSLogEntryLog}
.filter { $0.subsystem.contains(getSubsystem() }
.map{df.string(from: $0.date) + " " +
String(format:"0x%02x", $0.threadIdentifier) + " " +
String(format:"0x%x", $0.activityIdentifier) + " " +
String($0.processIdentifier) + " " +
$0.category + " " + $0.composedMessage}
return formattedLogs
} catch let err {
ZtaLogger().log.error("Failed to collect log: \(err)")
return []
}
}
}
It looks like getFormattedLogs() takes long time because we use filter to get message that logged by our app and format the log entry. Since compactMap is O(m+n) complexity, filter and map are O(n) that cause performance issue. Is there a better way to get logs from our app via OSLog? Could retrieving logs be called in appDidEnterBackground()?
Thanks,
Ying
Post not yet marked as solved
I'm having an issue with logging on my system (Sonoma 14.3.1), in that log messages disappear after 60-90 seconds, despite logging being configured to persist. This seems to happen across all subsystems.
The symptoms are:
• Watching the log stream in Console.app, messages older than 60-90 seconds disappear, even if no new messages are coming in.
• log show --last 2d only returns messages from the last couple of minutes.
I've filed FB13616761, but wondered if anyone had any other insights or suggestions. TIA
Post not yet marked as solved
Hi Team,
I am creating an application which is based on tele communications testing where I need to retrieve the SIP logs from the device.
How can we achieve?
Any approach apple team suggest which will be highly appreciated.
Thank You,
Vijay
Post not yet marked as solved
I'm trying to figure out how to maximize the value of structured logging in my project. The log filtering improvements in Xcode 15 are great but limited to being able to control the logging at a fine-grained level. For example, if I want to always disable some chatty debug logs for a specific category.
Setting OSLogPreference solves this problem once you've installed it onto a device, but when running in debug mode on Xcode, it seems to ignore this and print everything.
Is there a way to apply OSLogPreference while running Xcode, or another way to selectively disable categories?
Post not yet marked as solved
What do I miss here?
root@MacBook-Pro /tmp # sw_vers
ProductName: macOS
ProductVersion: 13.6.1
BuildVersion: 22G313
root@MacBook-Pro /tmp # log config --mode "level: off"
root@MacBook-Pro /tmp # log config --status
System mode = INFO
root@MacBook-Pro /tmp # log config --mode "level: debug"
root@MacBook-Pro /tmp # log config --status
System mode = DEBUG
root@MacBook-Pro /tmp # log config --mode "level: off"
root@MacBook-Pro /tmp # log config --status
System mode = DEBUG
Post not yet marked as solved
Hi folks,
For accessing the logs, I’m using OSLogStore object. I want to be able to read logs from any previous run of my application.
I can of course do this:
// Open the log store.
var logStore = try OSLogStore(scope: .currentProcessIdentifier)
But this only allows me to retrieve logs from my current running process.
I can also do this:
// Open the log store.
var logStore = try OSLogStore(scope: .system)
But this only works if my App Sandbox entitlement is false.
I tried disabling the sandbox, and I was able to get to all the logs (which is good) but according to this page:
https://developer.apple.com/documentation/security/app_sandbox/
it says:
To distribute a macOS app through the Mac App Store, you must enable the App Sandbox capability
Since we are planning on distributing our app on the store, this presents a big problem for me.
(I didn't try submitting to TestFlight to see if it's really the case). I don’t know if there are exclusions or ways around this – I don’t see an entitlement that I can add which would allow access to the logs.
Does anyone know a way around this?
Thanks,
David
Post not yet marked as solved
Love the new console. but every time I open a new tab, it clear the console filter.
I have some info level log that is from Bluetooth and other. I want to collect those logs but I don't want those in the Console.
How can I keep the filter as copied to new window tab, like the search panel.
Post not yet marked as solved
Our application (which happens to run in an admin account, thus there's no problem authenticating) collects logs calling /usr/bin/log through NSTask.
Usually this works all right, but sometimes all we get is the header
Timestamp Thread Type Activity PID TTL
and nothing else. The tool finishes with a zero result code, we get nothing on stderr and just the header above on stdout, with a proper EOF (as determined by a zero-length availableData read from an NSFileHandle through the stdout pipe).
At the same moment, if the /usr/bin/log tool is run manually in a Terminal window with precisely the same arguments in the same user account the application runs in, we get the logs all right.
Any idea what might be the culprit and how to fix the problem? Thanks!