3

Using Unified Logging, I'm getting multiple copies of each log entry (23 to be exact). I'm wondering what I might be doing wrong.

I'm using Swift 4.1, Xcode 9.4.1, Console Version 1.0 (2.0.52), and building an iOS 11.0 app.

The relevant code looks like:

import os.log
...
// property
let log = OSLog(subsystem: Constants.subsystem, category: Constants.category)

override func viewDidLoad() {
    super.viewDidLoad()
    os_log("Useless message...", log: log, type: .debug)
}

And, in the Console (only showing the Message column), I get:

Console Output

Subsystem, Category, Time, and Process values are identical for every entry.

And, the output only shows once in Xcode's console window.

What silly thing have I done now? (Or, is this a bug?)


Update: I set a breakpoint at the log statement to test. It's only hit once, but as soon as it executes, the 23 entries show in the Console.

Update 2: added UUID to log for test: same result: UUID was the same in all 23 entries.

os_log("Useless message... %@", log: log, type: .debug, String(describing: UUID()))

Results: Console Output with UUID Added

Update 3: Fixed...
Cleaned the project, deleted derived data, erased the content in the simulator - all of which I'd done multiple times before.

This time, though, I also shut down, then restarted Xcode - and now it's working fine! Weirdness!

leanne
  • 7,940
  • 48
  • 77
  • Well, how many instances of this view are there? – Alexander Jul 24 '18 at 20:13
  • This can be checked with a `let uuid = UUID()` instance variable, added to os_log. – Fabian Jul 24 '18 at 20:17
  • @Alexander: only one instance - or should be, anyway! It's a single-view app, and I'm not doing anything weird with it. – leanne Jul 24 '18 at 20:30
  • @Purpose: added UUID test results to my question. – leanne Jul 24 '18 at 20:30
  • is this the only place that you're logging something with 'Useless message' or you're logging that in other classes as well? – mfaani Jul 24 '18 at 20:32
  • @Honey: I'm logging *useful* messages in several places - test cases as well as in the app itself. It's happening with all of them. – leanne Jul 24 '18 at 20:34
  • Odd, I don't know what it could be! – Alexander Jul 24 '18 at 20:34
  • Maybe a dependency ties into OSLog which does this? Is it only happening at that callsite? Maybe it disappears without `log: log` argument? – Fabian Jul 24 '18 at 20:36
  • @Purpose: the `log:` parameter requires an `OSLog` type value; it's not optional. I did try, for grins, to set up a `log2` value inside the function and use it instead. It did the same thing. – leanne Jul 24 '18 at 21:51
  • @leanne is this happening with every os_log call inside the whole app? Is it reproducible in a fresh project/target without dependencies? Do you have dependencies which may cause this? – Fabian Jul 24 '18 at 21:53
  • @Purpose: I had cleaned the app, removed derived data, and erased all content and settings in the simulator many times, without change. However, I just did all of those, then shut down and restarted Xcode - BOOM - it's working fine now. Aargh! I'll update my question... – leanne Jul 24 '18 at 22:06
  • @leanne hah! Not bad. – Fabian Jul 24 '18 at 22:12
  • it's 2023 and I can still catch this issue several times. very annoying – congnd Sep 01 '23 at 03:12

0 Answers0