Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide remote log read capability #17

Open
taunusflieger opened this issue Jan 18, 2023 · 1 comment
Open

Provide remote log read capability #17

taunusflieger opened this issue Jan 18, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@taunusflieger
Copy link
Owner

No description provided.

@taunusflieger taunusflieger added the enhancement New feature or request label Jan 18, 2023
@Vollbrecht
Copy link

there was a way presented around 2 months ago in the matrix chat iirc ( end of october), where you could siphon the log output and still dont loose the local log.

    use core::ffi::{c_char, c_int};
    use esp_idf_sys::{size_t, va_list};
    use log::info;

    extern "C" {
        #[allow(improper_ctypes)]
        pub fn vsnprintf(_: *mut c_char, _: size_t, _: *const c_char, _: va_list) -> c_int;
    }

    #[allow(improper_ctypes_definitions)]
    unsafe extern "C" fn vprintf_trampoline(arg1: *const c_char, arg2: va_list) -> c_int {
        const MAX_LEN: usize = 128;
        let mut buf = [0u8; MAX_LEN];
        let len = vsnprintf(buf.as_mut_ptr() as _, MAX_LEN as _, arg1, arg2);
        if len < 0 {
            info!("vsnprintf returned an error: {len}");
            return len;
        }
        let s = &buf[0..(len as usize).min(MAX_LEN)]; // the min is just in case
        match core::str::from_utf8(s) {
            Ok(s) => info!("esp log received: {s}"),
            Err(err) => info!("esp log received a non-utf8 string: {err}, {s:?}"),
        }
        len
    }
    unsafe { esp_idf_sys::esp_log_set_vprintf(Some(vprintf_trampoline)) };
    esp_idf_svc::log::EspLogger::initialize_default();

hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants