Code Monkey home page Code Monkey logo

Comments (1)

Vollbrecht avatar Vollbrecht commented on July 22, 2024

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

from anemometer.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.