When running the code below, only the first entry gets logged.
Structured logging seems not to work when there are emoticons or object descriptions in the message. Is this by design?
let logger = Logger(subsystem: "TestSystem", category: "TestCategory")
logger.log("👍") // Result = 👍
let someEmoji:String = "👎"
logger.log("\(someEmoji)") // Result = empty log line
let someObjectDescription:String = String(describing:self)
logger.log("\(someObjectDescription)") // Result = empty log line
Post not yet marked as solved
Hello folks,
I would like to incrementally retrieve logs of my iOS App from the Unified Logging System using OSLogStore.
First I initialize the store
store = try OSLogStore(scope: .currentProcessIdentifier)
Second I set a position from which I want the logs using either :
position = store.position(timeIntervalSinceLatestBoot: 0) // to get the logs from the launch of the App
position = store.position(date: Date().addingTimeInterval(-10)) // to get the logs of the last 10 seconds
Third I get the entries in the store from the position
store.getEntries(at: position)
Issue
Whatever the position I set using from OSLogStore:
position(timeIntervalSinceLatestBoot:)
position(date:)
position(timeIntervalSinceEnd:)
All the logs are retrieved. I cannot get only the subset requested by the timeframe I specified
Sample
A sample LogScreen that has 2 buttons is attached to the post
1 to fetch logs since the last time they have been fetched
1 to add a log
The code has been simplified to ease the comprehension of the case, please be indulgent to the shortcuts that have been taken.
LogScreen.swift
References
https://developer.apple.com/documentation/oslog/oslogstore
https://developer.apple.com/forums/thread/705868
https://developer.apple.com/videos/play/wwdc2023/10226/
Environment
XCode 15b7
iPhone 14 Pro / iOS 17
Hi!
I am getting all debug output in text only format, without structure or color. I only noticed now after watching the respective WWDC session in Xcode 15 beta 8, but I am pretty sure this was the case in the previous betas as well. Is the new structured debug console activated by some setting I am overlooking?
Using the latest Xcode 15 Beta 7: In an existing project, I can't get structured logging to work as described. For new projects, it works fine but I must have some setting or value in an existing project that prevents it from working.
My simple text case:
In an existing project file:
@main
struct LuarasBooksApp: App {
var body: some Scene {
WindowGroup {
Text("hi")
.onAppear {
Logger(subsystem: "test", category: "test").error("help me")
}
}
}
}
The debug console looks like this:
That same code in a new project for the same Xcode 15 Beta 7 looks correct:
Are there any settings, variables, etc... related to logging or the console that might cause this difference? In the existing project it makes no difference to toggle the various metadata options on and off.
Thanks!
I wanted to try structured logging with os_log in C++, but I found that it fails to print anything given a format string and a variable:
eg.
void example(std::string& str)
{
os_log_info(OS_LOG_DEFAULT, "%s", str.c_str());
os_log_debug(OS_LOG_DEFAULT, "%s", str.c_str());
os_log_error(OS_LOG_DEFAULT, "%s", str.c_str());
}
This prints a blank row in the console, but with no text.
How is this meant to work with variables? It only works with literals and constants now as far as I can tell.
I'm looking forward to getting this working.