Skip to content

Commit f1f8660

Browse files
committed
Add instructions on how to see redacted logs and debug
1 parent 26e8cce commit f1f8660

File tree

6 files changed

+85
-9
lines changed

6 files changed

+85
-9
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ If you're using Xcode, you can develop for `sourcekit-bazel-bsp` by directly ope
99
## VSCode / Cursor
1010

1111
Download and install [the official Swift extension for Cursor / VSCode.](https://marketplace.visualstudio.com/items?itemName=swiftlang.swift-vscode) After this, the IDE should properly recognize sourcekit-bazel-bsp as a SwiftPM project and automatically generate the relevant build/debug actions. After building, you can test your custom binary by changing the path to sourcekit-bazel-bsp in your test project's BSP json file as described in the [Initial Setup](https://github.com/spotify/sourcekit-bazel-bsp?tab=readme-ov-file#initial-setup-instructions) instructions.
12+
13+
## Debugging and Troubleshooting
14+
15+
Instructions on how to debug sourcekit-bazel-bsp and enable extended logging are currently available at the main README.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>PayloadContent</key>
6+
<array>
7+
<dict>
8+
<key>PayloadDisplayName</key>
9+
<string>Enable Extended Logging</string>
10+
<key>PayloadEnabled</key>
11+
<true/>
12+
<key>PayloadIdentifier</key>
13+
<string>com.apple.system.logging.A8602F50-0DC2-43C5-8BBE-173B14BB0B5F</string>
14+
<key>PayloadType</key>
15+
<string>com.apple.system.logging</string>
16+
<key>PayloadUUID</key>
17+
<string>A8602F50-0DC2-43C5-8BBE-173B14BB0B5F</string>
18+
<key>PayloadVersion</key>
19+
<integer>1</integer>
20+
<key>Subsystems</key>
21+
<dict>
22+
<key>com.spotify.sourcekit-bazel-bsp</key>
23+
<dict>
24+
<key>DEFAULT-OPTIONS</key>
25+
<dict>
26+
<key>Enable-Private-Data</key>
27+
<true/>
28+
</dict>
29+
</dict>
30+
</dict>
31+
</dict>
32+
</array>
33+
<key>PayloadDescription</key>
34+
<string>Enables extended logging for sourcekit-bazel-bsp, exposing potentially sensitive information.</string>
35+
<key>PayloadDisplayName</key>
36+
<string>Extended sourcekit-bazel-bsp Logging</string>
37+
<key>PayloadIdentifier</key>
38+
<string>com.spotify.sourcekit-bazel-bsp.enable-extended-logging</string>
39+
<key>PayloadRemovalDisallowed</key>
40+
<false/>
41+
<key>PayloadScope</key>
42+
<string>System</string>
43+
<key>PayloadType</key>
44+
<string>Configuration</string>
45+
<key>PayloadUUID</key>
46+
<string>98EC5C60-67D6-4F3F-9EB7-50293291D03F</string>
47+
<key>PayloadVersion</key>
48+
<integer>1</integer>
49+
</dict>
50+
</plist>

Example/.vscode/tasks.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"label": "Build HelloWorld",
66
"type": "shell",
77
"command": "bazelisk",
8-
"args": ["build", "//HelloWorld"],
8+
"args": [
9+
"build",
10+
"//HelloWorld"
11+
],
912
"group": {
1013
"kind": "build",
1114
"isDefault": true
@@ -19,7 +22,10 @@
1922
"label": "Test HelloWorldTests",
2023
"type": "shell",
2124
"command": "bazelisk",
22-
"args": ["test", "//HelloWorld:HelloWorldTests"],
25+
"args": [
26+
"test",
27+
"//HelloWorld:HelloWorldTests"
28+
],
2329
"group": {
2430
"kind": "test",
2531
"isDefault": true
@@ -63,9 +69,9 @@
6369
}
6470
},
6571
{
66-
"label": "Stream SourceKit Logs",
72+
"label": "Stream SourceKitBazelBSP Logs",
6773
"type": "shell",
68-
"command": "log stream --process sourcekit-bazel-bsp --info",
74+
"command": "log stream --process sourcekit-bazel-bsp --debug",
6975
"problemMatcher": [],
7076
"isBackground": false,
7177
"presentation": {
@@ -74,4 +80,4 @@
7480
}
7581
}
7682
]
77-
}
83+
}

Example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ See the main README for a description of what is and isn't supported at the mome
2828

2929
## Troubleshooting
3030

31-
If something weird (or nothing) happens, check the `SourceKit-LSP: Indexing` logs for details of what may have happened. If you don't see that option at all, first run `Cmd+S` on a Swift file to see if that does the trick, and if it's still not there, you can instead log sourcekit-bazel-bsp by running `log stream --process sourcekit-bazel-bsp --info` on a terminal session. If you see no logs there when interacting with the IDE, that means one or more of the above steps were not followed correctly (most likely the build step).
31+
If something weird (or nothing) happens, check the `SourceKit-LSP: Indexing` logs for details of what may have happened. If you don't see that option at all, first run `Cmd+S` on a Swift file to see if that does the trick, and if it's still not there, try logging sourcekit-bazel-bsp directly by following the troubleshooting instructions in the main README.

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,24 @@
4040

4141
After following these steps, the `SourceKit Language Server` output tab (_Cmd+Shift+U_) should show up when opening Swift or Obj-C files, and indexing-related actions will start popping up at the bottom of the IDE after a while alongside a new `SourceKit-LSP: Indexing` output tab when working with those files.
4242

43-
If you experience any trouble trying to get it to work, check out the [Example/ folder](./Example) for a test project with a pre-configured Bazel and `.bsp` setup. The example project also contains instructions on how to debug sourcekit-bazel-bsp that can help you find and fix the problem.
43+
If you experience any trouble trying to get it to work, check out the [Example/ folder](./Example) for a test project with a pre-configured Bazel and `.bsp` setup. The _Troubleshooting_ section below also contains instructions on how to debug sourcekit-bazel-bsp.
4444

4545
### Other IDEs
4646

4747
The setup instructions depend on how the IDE integrates with LSPs. You should then search for instructions on how to install sourcekit-lsp on your IDE of choice and enable background indexing. After that, follow the `.bsp/` related steps from the above instructions. Keep in mind that this since project is developed specifically with Cursor / VSCode in mind, we cannot say how well sourcekit-bazel-bsp would work with other IDEs.
48+
49+
## Troubleshooting
50+
51+
### Seeing sourcekit-bazel-bsp's logs
52+
53+
sourcekit-bazel-bsp uses Apple's OSLog infrastructure under the hood. To see the tool's logs, run `log stream --process sourcekit-bazel-bsp --debug` on a terminal session.
54+
55+
By default, most logs will be redacted for privacy reasons, but you may want to see them for debug and development reasons. To enable extended logging and expose those logs, install the configuration profile at https://github.com/swiftlang/sourcekit-lsp/blob/main/Documentation/Enable%20Extended%20Logging.mobileconfig [as described here](https://support.apple.com/guide/mac-help/configuration-profiles-standardize-settings-mh35561/mac#mchlp41bd550) You will then able to see the redacted logs.
56+
57+
If you wish for the logs to become redacted again, you can remove the configuration profile [as described here.](https://support.apple.com/guide/mac-help/configuration-profiles-standardize-settings-mh35561/mac#mchlpa04df41.)
58+
59+
### Debugging
60+
61+
Since sourcekit-bazel-bsp is initialized from within sourcekit-lsp, debugging it requires you to start a lldb session in advance. You can do it with the following command: `lldb --attach-name sourcekit-bazel-bsp --wait-for`
62+
63+
Once the lldb session is initialized, triggering the initialization of the Swift extension on your IDE of choice (e.g. opening a Swift file in VSCode) should eventually cause lldb to start a debugging session.

Sources/SourceKitBazelBSP/SharedUtils/Logger.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import Foundation
2121
import OSLog
2222

23-
/// Simple helper to create loggers under the `sourcekit-bazel-bsp` subsystem.
23+
/// Simple helper to create loggers under the `com.spotify.sourcekit-bazel-bsp` subsystem.
2424
package func makeFileLevelBSPLogger(withCategory category: String = #fileID) -> Logger {
25-
Logger(subsystem: "sourcekit-bazel-bsp", category: category)
25+
Logger(subsystem: "com.spotify.sourcekit-bazel-bsp", category: category)
2626
}

0 commit comments

Comments
 (0)