[USRP-users] UHD logging: Are errors not handled through std::clog the same way as infos are? Or: How to implement a custom logging facility when restricted to the UHD C API?

Marcus Müller marcus.mueller at ettus.com
Mon Mar 4 16:45:44 EST 2019


Dear Janos
On Mon, 2019-03-04 at 18:22 +0100, Janos Buttgereit via USRP-users
wrote:
> Hi,
> 
> I’m using the UHD C API from within a C++ application. The reason for
> that is that UHD is optionally loaded as dynamic library at runtime
> through dlopen in case the user wants to use an ettus device and has
> the uhd library installed and therefore I’m limited to only use
> functions declared as extern C.

No, that's not true – C++ functions are just as exported. They might
not have the naming you expect, but it really doesn't make a difference
to the underlying system whether your exposed functions are C or C++.
That is, AS LONG as you used the same compiler to compile UHD and your
main C++ program (C++ ABI isn't as canonical as I'd like it to be).
I haven't worked with it in a while, but Boost.DLL [1] might be quite
exactly what you're looking for.

> 
> I need some custom logging facility for my application as it is GUI
> based, e.g. certain errors should end up in alert windows and not in
> console prints. However I haven’t found any possibility to implement
> such logging when restricted to the C API only. So first question:
> Did I overlook something? Any pointer on how to get custom logging
> working without using the C++ API would be greatly appreciated.

The C API was never meant to give you the full C++-specific flexibility
– I doubt this will be reasonably complex when going through the C API.


> 
> In the meantime I tried to go a different way. This document 
> https://files.ettus.com/manual/page_logging.html tells me, that UHD
> uses std::clog for everything using the console logging backend. As
> no other part of my application makes use of std::clog I simply
> redirected std::clog to a custom std::streambuf instance where I
> handle the log strings. This works quite well for the [INFO] log
> messages, however [ERROR] messages seem to bypass std::clog and are
> still printed to the console. Is this intended behaviour or a bug as
> the document tells that all console logging goes through std::clog?

I must admit: a good question.

Best regards,
Marcus




More information about the USRP-users mailing list