mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-29 12:06:01 +02:00
fix(log): use Swift OSLog instead of oslog Rust binding (#262)
This commit is contained in:
committed by
GitHub
parent
22f987bf24
commit
961602bd1b
Generated
+28
-58
@@ -959,19 +959,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dashmap"
|
||||
version = "5.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"hashbrown",
|
||||
"lock_api",
|
||||
"once_cell",
|
||||
"parking_lot_core 0.9.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "der"
|
||||
version = "0.5.1"
|
||||
@@ -1831,9 +1818,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "0.2.8"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
|
||||
checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
|
||||
dependencies = [
|
||||
"bytes 1.4.0",
|
||||
"fnv",
|
||||
@@ -2707,6 +2694,15 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_threads"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc"
|
||||
version = "0.2.7"
|
||||
@@ -2802,17 +2798,6 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "oslog"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "80d2043d1f61d77cb2f4b1f7b7b2295f40507f5f8e9d1c8bf10a1ca5f97a3969"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"dashmap",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
@@ -3108,7 +3093,7 @@ dependencies = [
|
||||
"line-wrap",
|
||||
"quick-xml",
|
||||
"serde",
|
||||
"time 0.3.18",
|
||||
"time 0.3.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4273,7 +4258,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri"
|
||||
version = "2.0.0-alpha.3"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#6aaba83476339fa413fe34d28877a932cb485117"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#105fe3fa242df87ad7655b519b0c01c3da9d8ee4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"attohttpc",
|
||||
@@ -4323,7 +4308,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-build"
|
||||
version = "2.0.0-alpha.1"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#6aaba83476339fa413fe34d28877a932cb485117"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#105fe3fa242df87ad7655b519b0c01c3da9d8ee4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cargo_toml",
|
||||
@@ -4342,7 +4327,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-codegen"
|
||||
version = "2.0.0-alpha.1"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#6aaba83476339fa413fe34d28877a932cb485117"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#105fe3fa242df87ad7655b519b0c01c3da9d8ee4"
|
||||
dependencies = [
|
||||
"base64 0.21.0",
|
||||
"brotli",
|
||||
@@ -4358,7 +4343,7 @@ dependencies = [
|
||||
"sha2 0.10.6",
|
||||
"tauri-utils",
|
||||
"thiserror",
|
||||
"time 0.3.18",
|
||||
"time 0.3.15",
|
||||
"url",
|
||||
"uuid",
|
||||
"walkdir",
|
||||
@@ -4367,7 +4352,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-macros"
|
||||
version = "2.0.0-alpha.1"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#6aaba83476339fa413fe34d28877a932cb485117"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#105fe3fa242df87ad7655b519b0c01c3da9d8ee4"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@@ -4453,12 +4438,13 @@ dependencies = [
|
||||
"byte-unit",
|
||||
"fern",
|
||||
"log",
|
||||
"oslog",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"swift-rs",
|
||||
"tauri",
|
||||
"time 0.3.18",
|
||||
"tauri-build",
|
||||
"time 0.3.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4587,7 +4573,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "0.13.0-alpha.1"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#6aaba83476339fa413fe34d28877a932cb485117"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#105fe3fa242df87ad7655b519b0c01c3da9d8ee4"
|
||||
dependencies = [
|
||||
"gtk",
|
||||
"http",
|
||||
@@ -4608,7 +4594,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-runtime-wry"
|
||||
version = "0.13.0-alpha.1"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#6aaba83476339fa413fe34d28877a932cb485117"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#105fe3fa242df87ad7655b519b0c01c3da9d8ee4"
|
||||
dependencies = [
|
||||
"cocoa",
|
||||
"gtk",
|
||||
@@ -4628,7 +4614,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-utils"
|
||||
version = "2.0.0-alpha.1"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#6aaba83476339fa413fe34d28877a932cb485117"
|
||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#105fe3fa242df87ad7655b519b0c01c3da9d8ee4"
|
||||
dependencies = [
|
||||
"brotli",
|
||||
"ctor",
|
||||
@@ -4745,29 +4731,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.18"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af0097eaf301d576d0b2aead7a59facab6d53cc636340f0291fab8446a2e8613"
|
||||
checksum = "d634a985c4d4238ec39cacaed2e7ae552fbd3c476b552c1deac3021b7d7eaf0c"
|
||||
dependencies = [
|
||||
"itoa 1.0.5",
|
||||
"serde",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2"
|
||||
dependencies = [
|
||||
"time-core",
|
||||
"libc",
|
||||
"num_threads",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5698,7 +5668,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "wry"
|
||||
version = "0.27.0"
|
||||
source = "git+https://github.com/tauri-apps/wry?branch=dev#9975dda12a122051b375ec6485650546d2d91c26"
|
||||
source = "git+https://github.com/tauri-apps/wry?branch=dev#7795356a45b1bd015fad0e9973fc5af58c8c339b"
|
||||
dependencies = [
|
||||
"base64 0.13.1",
|
||||
"block",
|
||||
|
||||
@@ -9,6 +9,9 @@ rust-version.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build.workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
@@ -23,7 +26,7 @@ fern = "0.6"
|
||||
android_logger = "0.11"
|
||||
|
||||
[target."cfg(target_os = \"ios\")".dependencies]
|
||||
oslog = "0.2"
|
||||
swift-rs = { git = "https://github.com/Brendonovich/swift-rs", rev = "eb6de914ad57501da5019154d476d45660559999" }
|
||||
|
||||
[features]
|
||||
colored = ["fern/colored"]
|
||||
+12
-9
@@ -1,12 +1,15 @@
|
||||
fn alias(alias: &str, has_feature: bool) {
|
||||
if has_feature {
|
||||
println!("cargo:rustc-cfg={alias}");
|
||||
}
|
||||
}
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::process::exit;
|
||||
|
||||
fn main() {
|
||||
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
|
||||
let mobile = target_os == "ios" || target_os == "android";
|
||||
alias("desktop", !mobile);
|
||||
alias("mobile", mobile);
|
||||
if let Err(error) = tauri_build::mobile::PluginBuilder::new()
|
||||
.ios_path("ios")
|
||||
.run()
|
||||
{
|
||||
println!("{error:#}");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/config/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
||||
Package.resolved
|
||||
/tauri-api
|
||||
@@ -0,0 +1,31 @@
|
||||
// swift-tools-version:5.7
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "tauri-plugin-log",
|
||||
platforms: [
|
||||
.iOS(.v11),
|
||||
],
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "tauri-plugin-log",
|
||||
type: .static,
|
||||
targets: ["tauri-plugin-log"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(name: "Tauri", path: "tauri-api")
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||
.target(
|
||||
name: "tauri-plugin-log",
|
||||
dependencies: [
|
||||
.byName(name: "Tauri")
|
||||
],
|
||||
path: "Sources")
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
# Log
|
||||
|
||||
Exposes a function log a message using the OSLog API.
|
||||
@@ -0,0 +1,13 @@
|
||||
import UIKit
|
||||
import Tauri
|
||||
import SwiftRs
|
||||
|
||||
@_cdecl("tauri_log")
|
||||
func log(level: Int, message: UnsafePointer<SRString>) {
|
||||
switch level {
|
||||
case 1: Logger.debug(message.pointee.to_string())
|
||||
case 2: Logger.info(message.pointee.to_string())
|
||||
case 3: Logger.error(message.pointee.to_string())
|
||||
default: break
|
||||
}
|
||||
}
|
||||
+15
-21
@@ -22,6 +22,11 @@ use tauri::{
|
||||
|
||||
pub use fern;
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
extern "C" {
|
||||
fn tauri_log(level: u8, message: &swift_rs::SRString);
|
||||
}
|
||||
|
||||
const DEFAULT_MAX_FILE_SIZE: u128 = 40000;
|
||||
const DEFAULT_ROTATION_STRATEGY: RotationStrategy = RotationStrategy::KeepOne;
|
||||
const DEFAULT_LOG_TARGETS: [LogTarget; 2] = [LogTarget::Stdout, LogTarget::LogDir];
|
||||
@@ -260,29 +265,18 @@ impl Builder {
|
||||
}
|
||||
#[cfg(target_os = "ios")]
|
||||
LogTarget::Stdout | LogTarget::Stderr => {
|
||||
use std::sync::Mutex;
|
||||
let loggers: Mutex<HashMap<String, oslog::OsLog>> = Default::default();
|
||||
let mut subsystem = String::new();
|
||||
let identifier = &app_handle.config().tauri.bundle.identifier;
|
||||
let s = identifier.split('.');
|
||||
let last = s.clone().count() - 1;
|
||||
for (i, w) in s.enumerate() {
|
||||
if i != last {
|
||||
subsystem.push_str(w);
|
||||
subsystem.push('.');
|
||||
}
|
||||
}
|
||||
subsystem.push_str(&app_handle.package_info().crate_name);
|
||||
|
||||
fern::Output::call(move |record| {
|
||||
let mut loggers = loggers.lock().unwrap();
|
||||
let pair =
|
||||
loggers.entry(record.target().into()).or_insert_with(|| {
|
||||
oslog::OsLog::new(&subsystem, record.target())
|
||||
});
|
||||
|
||||
let message = format!("{}", record.args());
|
||||
(*pair).with_level(record.level().into(), &message);
|
||||
unsafe {
|
||||
tauri_log(
|
||||
match record.level() {
|
||||
log::Level::Trace | log::Level::Debug => 1,
|
||||
log::Level::Info => 2,
|
||||
log::Level::Warn | log::Level::Error => 3,
|
||||
},
|
||||
&message.as_str().into(),
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
#[cfg(desktop)]
|
||||
|
||||
Reference in New Issue
Block a user