-
Notifications
You must be signed in to change notification settings - Fork 36
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
Make log4cxx optional (?) #30
Comments
Another possibility would be to use Boost's logger, since Boost is already a dependency. But then we can also make the Boost logger support optional. |
Yeah but the thing is that Boost Logger is still too new to be considered :( |
I think that |
Some Windows users (poke @aescande) would also like to see the dependency made optional (or removed), to make Windows compilation easier. I guess we could wrap the |
Ok, this is more or less the case in |
After thinking about it, I think that having one handler stored as a static pointer to function is fine. If you want to enable logging then you got to define your handler. We can provide one printing on stdout by default. This is good enough I think :) |
I guess we need at least |
Yeah but this can just be an enum to keep a simple interface. |
We can consider something like: // Register logging functions
registerLogger (INFO, ...);
registerLogger (ERROR, ...);
...
// Log some information
log (INFO, "something amazing happened"); |
Having this API is fine, my recommendation is to only have one underlying static variable to minimize issues with initialization/destruction as well as potential concurrency issues with multi-threading. It is reasonable to make the assumption that you don't change the logger while solving a problem but the log method must be thread safe... |
We can also have multiple logger instances defined by some identifier (e.g. string such as getLogger ("roboptim.core").log (INFO, "log message"); This seems to be what log4cxx is doing. This can be done with a unique global map, and Thread-safety is indeed my main concern (and the usual thorn in the side of developers when dealing with loggers). |
This is why separating the issues is important. A logger is two things:
My suggestion is keeping 1. minimum, one static object, one function to set it. For 1. I feel that omniorb had it right: http://omniorb.sourceforge.net/omni40/omniORB/omniORB004.html namespace omniORB { You may want to make it slightly more complicated with severities but not too much more. The for 2. lockless structures in boost can be the solution. Then you got that then you can write on the disk whatever you want later. |
Another thing to consider: a simple |
Converting a matrix to a string is too slow to be done synchronously so ultimately, it is better either to copy (for small objects) or to keep a shared pointer (for bigger ones, if possible) so that you can do that separately. One solution is to add directly into the logger the possibility to log basic types such as double, matrices and vectors to defer the transformation. Ultimately if the data volume is too important, relying on binary logging may be needed. |
This was just a dummy example, plus logging should be kept to a minimum in most cases (except in debugging scenarios where performance does not really matter). Being able to store expressions simply containing references/pointers to large data would indeed be an interesting solution, but this is probably overkill in this case (and probably requires a lot of work). This could probably be part of a standalone logging library that could then be used in the user-defined logging functions considered here, but this would imply using a more complex log function signature... I think that for now, we should keep things simple (thread-safe, handling strings and stringstream expressions), and leave the heavy-lifting to the user-defined log functions (possibly calling |
Yeah, of course. My only point is that if you make an interface at some point, it is better to have it take directly the object you want to log (matrices...) than strings as it will allow you to process them on the logger side. |
For this, defining a |
Yeah something like that. I would be more in favor to just use an abstract class to avoid the maintenance cost of the template. A more complex design could allow the user to register its own type but again this seems a bit too much knowing that we mainly log vector and matrices. |
No description provided.
The text was updated successfully, but these errors were encountered: