Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libssh logging callback ssh_set_log_callback()

Tags:

c++

libssh

I am writing an application which uses libssh, which logs to stderr by default. I would like to capture the logging to so I can do something useful with it.

Libssh provides some functions seemingly for this purpose, but I can't seem to get them to work. The documentation is limited and I can't seem to find much out there.

The function provided in libssh/callbacks.h is int ssh_set_log_callback ( ssh_logging_callback cb ) documented here.

ssh_logging_callback is documented here

I have the following code in my app:

static void ssh_log_function(int priority, const char *function, const char *buffer, void *userdata)
{
    cout << priority << " " << function << endl << buffer << endl;
    cout << "And now for something completely different" << endl;
}

Then later in my app, before I execute some libssh commands, I have this:

ssh_set_log_callback(ssh_log_function);

When I compile and execute, I get the usual logging output to stderr and no sign of the function I created running.

Have I missed something or am I doing it completely wrong? I have tried passing &ssh_log_function as well but it didn't make any difference.

Would appreciate any help! Thanks!

like image 930
JoGoFo Avatar asked Apr 16 '26 17:04

JoGoFo


1 Answers

For anyone interested, I managed to get this working and the above code works. I was simply setting the log level to an uninitialised integer later on in my code. /Fail

Hope this helps someone else.

like image 171
JoGoFo Avatar answered Apr 19 '26 07:04

JoGoFo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!