Some checks failed
Audit / audit-js (push) Failing after 0s
bench / bench (map[os:ubuntu-latest runner:xvfb-run --auto-servernum target:x86_64-unknown-linux-gnu], nightly) (push) Failing after 0s
covector version or publish / run-integration-tests (ubuntu-latest) (push) Failing after 0s
Audit / audit-rust (push) Failing after 0s
test `@tauri-apps/cli` / test (ubuntu-latest) (push) Failing after 0s
test `tauri-cli` / test (map[os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
deploy schema worker / deploy (push) Failing after 0s
lint rust / clippy (map[cargo:cargo include: os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
lint rust / clippy (map[cargo:cross include:--package api os:ubuntu-latest target:aarch64-linux-android]) (push) Failing after 0s
supply chain health status / check rust dependencies with cargo vet (push) Failing after 0s
test `@tauri-apps/api` e2e (mobile) / android (push) Failing after 0s
test `@tauri-apps/api` e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
Udeps / changes (push) Failing after 0s
Udeps / setup (push) Has been skipped
Udeps / udeps (push) Has been skipped
bench / bench (map[os:macos-latest runner: target:aarch64-apple-darwin], nightly) (push) Has been cancelled
bench / bench (map[os:windows-latest runner: target:x86_64-pc-windows-msvc], nightly) (push) Has been cancelled
covector version or publish / run-integration-tests (macos-latest) (push) Has been cancelled
covector version or publish / run-integration-tests (windows-latest) (push) Has been cancelled
covector version or publish / version-or-publish (push) Has been cancelled
test `@tauri-apps/cli` / test (macos-latest) (push) Has been cancelled
test `tauri-cli` / test (map[args:--no-default-features --features native-tls-vendored os:windows-latest restore-only:true target:aarch64-pc-windows-msvc]) (push) Has been cancelled
test `tauri-cli` / test (map[os:macos-latest target:x86_64-apple-darwin]) (push) Has been cancelled
test `tauri-cli` / test (map[os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:macos-latest target:aarch64-apple-darwin]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include:--package api os:macos-latest target:aarch64-apple-ios]) (push) Has been cancelled
test `@tauri-apps/api` e2e (mobile) / ios (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
test `@tauri-apps/cli` / test (windows-latest) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
140 lines
3.7 KiB
Swift
140 lines
3.7 KiB
Swift
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import os.log
|
|
import UIKit
|
|
import Foundation
|
|
|
|
class StdoutRedirector {
|
|
private var originalStdout: Int32 = -1
|
|
private var originalStderr: Int32 = -1
|
|
private var stdoutPipe: [Int32] = [-1, -1]
|
|
private var stderrPipe: [Int32] = [-1, -1]
|
|
private var stdoutReadSource: DispatchSourceRead?
|
|
private var stderrReadSource: DispatchSourceRead?
|
|
|
|
func start() {
|
|
originalStdout = dup(STDOUT_FILENO)
|
|
originalStderr = dup(STDERR_FILENO)
|
|
|
|
guard Darwin.pipe(&stdoutPipe) == 0,
|
|
Darwin.pipe(&stderrPipe) == 0 else {
|
|
Logger.error("Failed to create stdout/stderr pipes")
|
|
return
|
|
}
|
|
|
|
dup2(stdoutPipe[1], STDOUT_FILENO)
|
|
dup2(stderrPipe[1], STDERR_FILENO)
|
|
close(stdoutPipe[1])
|
|
close(stderrPipe[1])
|
|
|
|
stdoutReadSource = createReader(
|
|
readPipe: stdoutPipe[0],
|
|
writeToOriginal: originalStdout,
|
|
label: "stdout"
|
|
)
|
|
|
|
stderrReadSource = createReader(
|
|
readPipe: stderrPipe[0],
|
|
writeToOriginal: originalStderr,
|
|
label: "stderr"
|
|
)
|
|
}
|
|
|
|
private func createReader(
|
|
readPipe: Int32,
|
|
writeToOriginal: Int32,
|
|
label: String
|
|
) -> DispatchSourceRead {
|
|
let source = DispatchSource.makeReadSource(
|
|
fileDescriptor: readPipe,
|
|
queue: .global(qos: .utility)
|
|
)
|
|
|
|
source.setEventHandler {
|
|
let bufferSize = 4096
|
|
var buffer = [UInt8](repeating: 0, count: bufferSize)
|
|
let bytesRead = read(readPipe, &buffer, bufferSize)
|
|
|
|
if bytesRead > 0 {
|
|
let output = String(
|
|
bytes: buffer[0..<bytesRead],
|
|
encoding: .utf8
|
|
) ?? ""
|
|
|
|
let trimmed = output.trimmingCharacters(in: .newlines)
|
|
if !trimmed.isEmpty {
|
|
// we're sending stderr to oslog, so we need to avoid recursive calls
|
|
if trimmed.hasPrefix("OSLOG-") {
|
|
// make sure the system can parse the oslogs
|
|
write(writeToOriginal, &buffer, bytesRead)
|
|
} else {
|
|
Logger.info("[\(label)] \(trimmed)")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
source.setCancelHandler {
|
|
close(readPipe)
|
|
}
|
|
|
|
source.resume()
|
|
return source
|
|
}
|
|
}
|
|
|
|
/// Wrapper class for os_log function
|
|
public class Logger {
|
|
private static var _enabled = false
|
|
public static var enabled: Bool {
|
|
get {
|
|
#if DEBUG
|
|
return true
|
|
#else
|
|
return _enabled
|
|
#endif
|
|
}
|
|
set {
|
|
Logger._enabled = newValue
|
|
}
|
|
}
|
|
|
|
static func log(_ items: [Any], category: String, type: OSLogType) {
|
|
if Logger.enabled {
|
|
var message = ""
|
|
let last = items.count - 1
|
|
for (index, item) in items.enumerated() {
|
|
message += "\(item)"
|
|
if index != last {
|
|
message += " "
|
|
}
|
|
}
|
|
|
|
let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "-", category: category)
|
|
os_log("%{public}@", log: log, type: type, String(message.prefix(4068)))
|
|
}
|
|
}
|
|
|
|
public static func debug(_ items: Any..., category: String = "app") {
|
|
#if DEBUG
|
|
Logger.log(items, category: category, type: OSLogType.default)
|
|
#else
|
|
Logger.log(items, category: category, type: OSLogType.debug)
|
|
#endif
|
|
}
|
|
|
|
public static func info(_ items: Any..., category: String = "app") {
|
|
#if DEBUG
|
|
Logger.log(items, category: category, type: OSLogType.default)
|
|
#else
|
|
Logger.log(items, category: category, type: OSLogType.info)
|
|
#endif
|
|
}
|
|
|
|
public static func error(_ items: Any..., category: String = "app") {
|
|
Logger.log(items, category: category, type: OSLogType.error)
|
|
}
|
|
}
|