Explore platform-specific debug logging #190

Open
opened 2020-08-06 16:56:24 +00:00 by gburd · 0 comments
gburd commented 2020-08-06 16:56:24 +00:00 (Migrated from github.com)

During development (and bug investigations), it's very helpful to see detailed logs of what's going on under the hood. On Android this looks like gathering logs via adb logcat, and other platforms have their own logging mechanisms.

This is of particular use for observing operation of something like sync, which is a potentially long-running operation that is highly depended on the "environment" for its success (mainly connectivity).

This issue is a placeholder for exploring passing in a platform-aware logger into something like sync.

An example of a very primitive but useful-enough Android-aware logger:

use std::os::raw::c_char;
use std::os::raw::c_int;
use std::ffi::CString;

pub const ANDROID_LOG_DEBUG: i32 = 3;
extern { pub fn __android_log_write(prio: c_int, tag: *const c_char, text: *const c_char) -> c_int; }

pub fn d(message: &str) {
    let message = CString::new(message).unwrap();
    let message = message.as_ptr();
    let tag = CString::new("RustyToodle").unwrap();
    let tag = tag.as_ptr();
    unsafe { __android_log_write(ANDROID_LOG_DEBUG, tag, message) };
}
During development (and bug investigations), it's very helpful to see detailed logs of what's going on under the hood. On Android this looks like gathering logs via `adb logcat`, and other platforms have their own logging mechanisms. This is of particular use for observing operation of something like sync, which is a potentially long-running operation that is highly depended on the "environment" for its success (mainly connectivity). This issue is a placeholder for exploring passing in a platform-aware logger into something like sync. An example of a very primitive but useful-enough Android-aware logger: ``` use std::os::raw::c_char; use std::os::raw::c_int; use std::ffi::CString; pub const ANDROID_LOG_DEBUG: i32 = 3; extern { pub fn __android_log_write(prio: c_int, tag: *const c_char, text: *const c_char) -> c_int; } pub fn d(message: &str) { let message = CString::new(message).unwrap(); let message = message.as_ptr(); let tag = CString::new("RustyToodle").unwrap(); let tag = tag.as_ptr(); unsafe { __android_log_write(ANDROID_LOG_DEBUG, tag, message) }; } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: greg/mentat#190
No description provided.