This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user-configuration of Noosphere log detail (#1016)
1. Allow user configuration of Noosphere log detail (persisted using AppDefaults) 2. Pipe `stdout` to a logger to capture Noosphere logs This is per-process on iOS and you can see the result via Console.app Intended to help with debugging #1008
- Loading branch information
1 parent
86b3c91
commit 21d3b08
Showing
8 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// NoosphereLogProxy.swift | ||
// Subconscious | ||
// | ||
// Created by Ben Follington on 20/12/2023. | ||
// | ||
|
||
import Foundation | ||
import os | ||
import OSLog | ||
|
||
public enum NoosphereLogProxy {} | ||
|
||
extension NoosphereLogProxy { | ||
public static let pipe = Pipe() | ||
static let logger = Logger( | ||
subsystem: Config.default.rdns, | ||
category: "StdOut" | ||
) | ||
|
||
/// Redirect STDOUT to a logger to capture it in production | ||
public static func connect() -> Void { | ||
// Adapted from https://stackoverflow.com/a/54124239 | ||
setvbuf(stdout, nil, _IONBF, 0) | ||
dup2(pipe.fileHandleForWriting.fileDescriptor, STDOUT_FILENO) | ||
|
||
pipe.fileHandleForReading.readabilityHandler = { handle in | ||
let data = handle.availableData | ||
let str = String( | ||
data: data, | ||
encoding: .ascii | ||
) ?? "<Non-ascii data of size\(data.count)>\n" | ||
DispatchQueue.main.async { | ||
logger.log("\(str, privacy: .public)") | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters