Closed Richienb closed 3 years ago
@Djiit Ping!
@Djiit Friendly ping!
Hey there :-)
I'm sorry I don't have much free time these days. Maybe you could open a PR with a proposed solution ?
Sure! I was going to do that initially except I've been getting dabbed on by the build requirements.
The code is pretty old as we speak. I'm more able to maintain the JS aspects, as I'm not the original author :), so yeah, any help is appreciated ! Thanks!
After some investigating, it appears that this line is the culprit:
https://github.com/wilix-team/iohook/blob/master/libuiohook/src/logger.c#L42
Somewhere in the native interface for this library, probably iohook.cc, you can do something like this:
bool logger_proc(unsigned int level, const char *format, ...) {
bool status = false;
va_list args;
switch (level) {
#ifdef USE_DEBUG
case LOG_LEVEL_DEBUG:
case LOG_LEVEL_INFO:
va_start(args, format);
status = vfprintf(stdout, format, args) >= 0;
va_end(args);
break;
#endif
case LOG_LEVEL_WARN:
case LOG_LEVEL_ERROR:
va_start(args, format);
// Alternatively, send the format and args to something other than stderr.
status = vfprintf(stderr, format, args) >= 0;
va_end(args);
break;
}
return status;
}
...
hook_set_logger_proc(&logger_proc);
I am not sure if node has a logging facility, but if it does, logger_proc
should probably interface with it instead of std output. For example, libuiohook to Java logging through JNI: https://github.com/kwhat/jnativehook/blob/2.1/src/jni/jni_Logger.c#L97
You shouldn't need to monkey around with libuiohook, only call hook_set_logger_proc
with a new function pointer from iohook.cc.
@kwhat I have no idea how to program in C++ but if we can somehow callback to the main javascript then it would be much easier to do logging.
@Richienb just console.log?
@kwhat console.log
in C++? We need to communicate back to the javascript code using a callback that is provided with the data.
Sorry, I am a bit of a novice at node outside of just using NPM to get and build stuff. It looks like iohook.cc already has a logger function setup, so the only thing that would need to be done would be to change that function to call a javascript function that does logging. This is effectively what is happening in the JNI example I provided earlier for the Java side of things using the built in java.util.logging.Logger. This library provides no javascript logging facility, so I am trying to figure out what we would call back to in logger_proc
which is why I was asking about console.log
. This function would just need to be updated to call out to the javascripts console methods to log instead of going out to stdout/stderr as it currently does. As I previously stated, I don't know much about node, but this seems to be the most basic method of logging in node. There are at least another 3 NPM logging libraries that do more advanced logging and the logger_proc
method could easily interface with any number of those by either using some type of configuration or some yet to be created iohook javascript logging facility. This logging facility would need to have a javascript method that is called from the native code directly (logger_proc) and it would need to call a callback function to do the logging. There should also be a default callback function and a method of setting the current callback function. There maybe a way to do this from the native code directly and just skip the javascript part, but it would probably be easier and cleaner to just do it in javascript. I will have to do some more digging.
@kwhat The easiest way to do this is to use a Nan Callback to pass on all the arguments logger_proc is provided with.
To stop the logs coming from iohook you need simply pass false in the start function const ioHook = require('iohook'); ioHook.start(false);
Will make sure this is in docs.
Added to doc.
Expected Behavior
iohook
should be imported without creating any noise in the terminal.Current Behavior
It is logging this:
Possible Solution
Silently perform this in the background and only alert if failed.
Steps to Reproduce (for bugs)
Context
I want to be able to silently import
iohook
without it spitting information in the terminal.Your Environment
cc @Djiit