Skip to content

Commit

Permalink
fix(Logging): add Rust logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Oct 24, 2024
1 parent 864954a commit 3e066d2
Show file tree
Hide file tree
Showing 32 changed files with 285 additions and 224 deletions.
13 changes: 9 additions & 4 deletions core/systems/launcher/interactive_process.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ var logger := Log.get_logger("InteractiveProcess", Log.LEVEL.INFO)


func _init(command: String, cmd_args: PackedStringArray = []) -> void:
# Hack for steam plugin running steamcmd on NixOS
if command.ends_with("steamcmd.sh"):
cmd = "steam-run"
args = PackedStringArray([command])
args.append_array(cmd_args)
return

cmd = command
args = cmd_args


## Start the interactive process
# TODO: Fixme
func start() -> int:
# Create a new PTY instance and start the process
self.pty = Pty.new()
Expand All @@ -47,13 +53,12 @@ func _on_line_written(line: String):
func send(input: String) -> void:
if not pty:
return
logger.info("Writing input: " + input)
if pty.write_line(input) < 0:
#if pty.write_line(input) < 0:
if pty.write(input.to_utf8_buffer()) < 0:
logger.debug("Unable to write to PTY")


## Read from the stdout of the running process
#TODO: Fixme
func read(_chunk_size: int = 1024) -> String:
if not pty:
logger.debug("Unable to read from closed PTY")
Expand Down
1 change: 1 addition & 0 deletions extensions/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions extensions/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ zvariant = "4.2.0"
gamescope-x11-client = { git = "https://github.com/ShadowBlip/gamescope-x11-client", branch = "main" }
inotify = "0.11.0"
byte-unit = "5.1.4"
log = "0.4.22"
12 changes: 6 additions & 6 deletions extensions/core/src/bluetooth/bluez.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl BluezInstance {
Err(e) => match e {
TryRecvError::Empty => break,
TryRecvError::Disconnected => {
godot_error!("Backend thread is not running!");
log::error!("Backend thread is not running!");
return;
}
},
Expand Down Expand Up @@ -221,15 +221,15 @@ impl BluezInstance {
impl IResource for BluezInstance {
/// Called upon object initialization in the engine
fn init(base: Base<Self::Base>) -> Self {
godot_print!("Initializing Bluez instance");
log::info!("Initializing Bluez instance");

// Create a channel to communicate with the service
let (tx, rx) = channel();

// Spawn a task using the shared tokio runtime to listen for signals
RUNTIME.spawn(async move {
if let Err(e) = run(tx).await {
godot_error!("Failed to run Bluez task: ${e:?}");
log::error!("Failed to run Bluez task: ${e:?}");
}
});

Expand Down Expand Up @@ -276,7 +276,7 @@ impl IResource for BluezInstance {
/// Runs Bluez tasks in Tokio to listen for DBus signals and send them
/// over the given channel so they can be processed during each engine frame.
async fn run(tx: Sender<Signal>) -> Result<(), RunError> {
godot_print!("Spawning Bluez tasks");
log::info!("Spawning Bluez tasks");
// Establish a connection to the system bus
let conn = get_dbus_system().await?;

Expand Down Expand Up @@ -330,7 +330,7 @@ async fn run(tx: Sender<Signal>) -> Result<(), RunError> {
let args = match signal.args() {
Ok(args) => args,
Err(e) => {
godot_warn!("Failed to get signal args: ${e:?}");
log::warn!("Failed to get signal args: ${e:?}");
continue;
}
};
Expand All @@ -356,7 +356,7 @@ async fn run(tx: Sender<Signal>) -> Result<(), RunError> {
let args = match signal.args() {
Ok(args) => args,
Err(e) => {
godot_warn!("Failed to get signal args: ${e:?}");
log::warn!("Failed to get signal args: ${e:?}");
continue;
}
};
Expand Down
12 changes: 5 additions & 7 deletions extensions/core/src/bluetooth/bluez/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ impl BluetoothAdapter {
/// Create a new [BluetoothAdapter] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
godot_print!("BluetoothAdapter created with path: {path}");
log::info!("BluetoothAdapter created with path: {path}");
let (tx, rx) = channel();
let dbus_path = path.clone().into();

// Spawn a task using the shared tokio runtime to listen for signals
RUNTIME.spawn(async move {
if let Err(e) = run(tx, dbus_path).await {
godot_error!("Failed to run DBusDevice task: ${e:?}");
log::error!("Failed to run DBusDevice task: ${e:?}");
}
});

Expand Down Expand Up @@ -176,9 +176,7 @@ impl BluetoothAdapter {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.clone().into()) {
if let Some(res) = resource_loader.load(res_path.clone().into()) {
godot_print!(
"Resource already exists with path '{res_path}', loading that instead"
);
log::info!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<BluetoothAdapter> = res.cast();
device
} else {
Expand Down Expand Up @@ -460,7 +458,7 @@ impl BluetoothAdapter {
Err(e) => match e {
TryRecvError::Empty => break,
TryRecvError::Disconnected => {
godot_error!("Backend thread is not running!");
log::error!("Backend thread is not running!");
return;
}
},
Expand Down Expand Up @@ -498,7 +496,7 @@ impl BluetoothAdapter {

impl Drop for BluetoothAdapter {
fn drop(&mut self) {
godot_print!("BluetoothAdapter '{}' is being destroyed!", self.dbus_path);
log::trace!("BluetoothAdapter '{}' is being destroyed!", self.dbus_path);
}
}

Expand Down
14 changes: 6 additions & 8 deletions extensions/core/src/bluetooth/bluez/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ impl BluetoothDevice {
/// Create a new [BluetoothDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
godot_print!("BluetoothDevice created with path: {path}");
log::info!("BluetoothDevice created with path: {path}");
let (tx, rx) = channel();
let dbus_path = path.clone().into();

// Spawn a task using the shared tokio runtime to listen for signals
RUNTIME.spawn(async move {
if let Err(e) = run(tx, dbus_path).await {
godot_error!("Failed to run BluetoothDevice task: ${e:?}");
log::error!("Failed to run BluetoothDevice task: ${e:?}");
}
});

Expand Down Expand Up @@ -173,9 +173,7 @@ impl BluetoothDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.clone().into()) {
if let Some(res) = resource_loader.load(res_path.clone().into()) {
godot_print!(
"Resource already exists with path '{res_path}', loading that instead"
);
log::info!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<BluetoothDevice> = res.cast();
device
} else {
Expand Down Expand Up @@ -455,7 +453,7 @@ impl BluetoothDevice {
Err(e) => match e {
TryRecvError::Empty => break,
TryRecvError::Disconnected => {
godot_error!("Backend thread is not running!");
log::error!("Backend thread is not running!");
return;
}
},
Expand All @@ -466,7 +464,7 @@ impl BluetoothDevice {

/// Process and dispatch the given signal
fn process_signal(&mut self, signal: Signal) {
godot_print!("Got signal: {signal:?}");
log::trace!("Got signal: {signal:?}");
match signal {
Signal::Updated => {
self.base_mut().emit_signal("updated".into(), &[]);
Expand All @@ -485,7 +483,7 @@ impl BluetoothDevice {

impl Drop for BluetoothDevice {
fn drop(&mut self) {
godot_print!("BluetoothDevice '{}' is being destroyed!", self.dbus_path);
log::trace!("BluetoothDevice '{}' is being destroyed!", self.dbus_path);
}
}

Expand Down
20 changes: 10 additions & 10 deletions extensions/core/src/disk/udisks2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ impl UDisks2Instance {
let partitions = block_device.bind().get_partitions();
if partitions.is_empty() {
if !self.partition_devices.contains_key(dbus_path) {
godot_print!(
log::info!(
"Adding {dbus_path} as unprotected device. It is not a partition_devices"
);
unprotected_devices.push(block_device.clone());
continue;
}
godot_print!("Skipping {dbus_path}. It is a partition_device.");
log::info!("Skipping {dbus_path}. It is a partition_device.");
} else {
for partition_device in partitions.iter_shared() {
let Some(filesystem_device) = partition_device.bind().get_filesystem() else {
godot_print!(
log::info!(
"Adding {dbus_path} as unprotected device. It does not have a FilesystemDevice"
);
unprotected_devices.push(block_device.clone());
Expand All @@ -198,7 +198,7 @@ impl UDisks2Instance {
}
}
}
godot_print!(
log::info!(
"Adding {dbus_path} as unprotected device. It does not have any mounts in PROTECTED_MOUNTS"
);
unprotected_devices.push(block_device.clone());
Expand All @@ -220,7 +220,7 @@ impl UDisks2Instance {
Err(e) => match e {
TryRecvError::Empty => break,
TryRecvError::Disconnected => {
godot_error!("Backend thread is not running!");
log::error!("Backend thread is not running!");
return;
}
},
Expand Down Expand Up @@ -314,15 +314,15 @@ impl UDisks2Instance {
impl IResource for UDisks2Instance {
/// Called upon object initialization in the engine
fn init(base: Base<Self::Base>) -> Self {
godot_print!("Initializing UDisks2 instance");
log::info!("Initializing UDisks2 instance");

// Create a channel to communicate with the service
let (tx, rx) = channel();

// Spawn a task using the shared tokio runtime to listen for signals
RUNTIME.spawn(async move {
if let Err(e) = run(tx).await {
godot_error!("Failed to run UDisks2 task: ${e:?}");
log::error!("Failed to run UDisks2 task: ${e:?}");
}
});

Expand Down Expand Up @@ -382,7 +382,7 @@ impl IResource for UDisks2Instance {
/// Runs UDisks2 tasks in Tokio to listen for DBus signals and send them
/// over the given channel so they can be processed during each engine frame.
async fn run(tx: Sender<Signal>) -> Result<(), RunError> {
godot_print!("Spawning UDisks2 tasks");
log::info!("Spawning UDisks2 tasks");
// Establish a connection to the system bus
let conn = get_dbus_system().await?;

Expand Down Expand Up @@ -436,7 +436,7 @@ async fn run(tx: Sender<Signal>) -> Result<(), RunError> {
let args = match signal.args() {
Ok(args) => args,
Err(e) => {
godot_warn!("Failed to get signal args: ${e:?}");
log::warn!("Failed to get signal args: ${e:?}");
continue;
}
};
Expand All @@ -462,7 +462,7 @@ async fn run(tx: Sender<Signal>) -> Result<(), RunError> {
let args = match signal.args() {
Ok(args) => args,
Err(e) => {
godot_warn!("Failed to get signal args: ${e:?}");
log::warn!("Failed to get signal args: ${e:?}");
continue;
}
};
Expand Down
8 changes: 3 additions & 5 deletions extensions/core/src/disk/udisks2/block_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl BlockDevice {
/// Create a new [BlockDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
godot_print!("BlockDevice created with path: {path}");
log::info!("BlockDevice created with path: {path}");

Gd::from_init_fn(|base| {
// Create a connection to DBus
Expand Down Expand Up @@ -87,9 +87,7 @@ impl BlockDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.clone().into()) {
if let Some(res) = resource_loader.load(res_path.clone().into()) {
godot_print!(
"Resource already exists with path '{res_path}', loading that instead"
);
log::info!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<BlockDevice> = res.cast();
device
} else {
Expand Down Expand Up @@ -151,6 +149,6 @@ impl BlockDevice {

impl Drop for BlockDevice {
fn drop(&mut self) {
godot_print!("BlockDevice '{}' is being destroyed!", self.dbus_path);
log::trace!("BlockDevice '{}' is being destroyed!", self.dbus_path);
}
}
8 changes: 3 additions & 5 deletions extensions/core/src/disk/udisks2/drive_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl DriveDevice {
/// Create a new [DriveDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
godot_print!("DriveDevice created with path: {path}");
log::info!("DriveDevice created with path: {path}");

Gd::from_init_fn(|base| {
// Create a connection to DBus
Expand Down Expand Up @@ -77,9 +77,7 @@ impl DriveDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.clone().into()) {
if let Some(res) = resource_loader.load(res_path.clone().into()) {
godot_print!(
"Resource already exists with path '{res_path}', loading that instead"
);
log::info!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<DriveDevice> = res.cast();
device
} else {
Expand Down Expand Up @@ -138,6 +136,6 @@ impl DriveDevice {

impl Drop for DriveDevice {
fn drop(&mut self) {
godot_print!("DriveDevice '{}' is being destroyed!", self.dbus_path);
log::trace!("DriveDevice '{}' is being destroyed!", self.dbus_path);
}
}
8 changes: 3 additions & 5 deletions extensions/core/src/disk/udisks2/filesystem_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl FilesystemDevice {
/// Create a new [FilesystemDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
godot_print!("FilesystemDevice created with path: {path}");
log::info!("FilesystemDevice created with path: {path}");

Gd::from_init_fn(|base| {
// Create a connection to DBus
Expand Down Expand Up @@ -64,9 +64,7 @@ impl FilesystemDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.clone().into()) {
if let Some(res) = resource_loader.load(res_path.clone().into()) {
godot_print!(
"Resource already exists with path '{res_path}', loading that instead"
);
log::info!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<FilesystemDevice> = res.cast();
device
} else {
Expand Down Expand Up @@ -106,6 +104,6 @@ impl FilesystemDevice {

impl Drop for FilesystemDevice {
fn drop(&mut self) {
godot_print!("FilesystemDevice '{}' is being destroyed!", self.dbus_path);
log::trace!("FilesystemDevice '{}' is being destroyed!", self.dbus_path);
}
}
8 changes: 3 additions & 5 deletions extensions/core/src/disk/udisks2/partition_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl PartitionDevice {
/// Create a new [PartitionDevice] with the given DBus path
pub fn from_path(path: GString) -> Gd<Self> {
// Create a channel to communicate with the signals task
godot_print!("PartitionDevice created with path: {path}");
log::info!("PartitionDevice created with path: {path}");

Gd::from_init_fn(|base| {
// Create a connection to DBus
Expand Down Expand Up @@ -109,9 +109,7 @@ impl PartitionDevice {
let mut resource_loader = ResourceLoader::singleton();
if resource_loader.exists(res_path.clone().into()) {
if let Some(res) = resource_loader.load(res_path.clone().into()) {
godot_print!(
"Resource already exists with path '{res_path}', loading that instead"
);
log::info!("Resource already exists with path '{res_path}', loading that instead");
let device: Gd<PartitionDevice> = res.cast();
device
} else {
Expand Down Expand Up @@ -175,6 +173,6 @@ impl PartitionDevice {

impl Drop for PartitionDevice {
fn drop(&mut self) {
godot_print!("PartitionDevice '{}' is being destroyed!", self.dbus_path);
log::trace!("PartitionDevice '{}' is being destroyed!", self.dbus_path);
}
}
Loading

0 comments on commit 3e066d2

Please sign in to comment.