Hi All,

Sometimes I find it very useful to switch the client api logging on.

The user interface is powerful but also not too comfortable.
So what about providing a little interface for easy usage as an example in the next Qpid release?

Maybe something like this header file QpidApiLogger.h:


#ifndef OWN_QPID_API_LOGGER_H
#define OWN_QPID_API_LOGGER_H

#include <qpid/messaging/Logger.h>

#include <string>
#include <vector>
#include <exception>

namespace helper {

/**
* Helper class which makes it easy to switch on logging of Qpid Client API.
 */
class QpidApiLogger
{
public:
enum LOG_LEVEL {LVL_TRACE, LVL_DEBUG, LVL_INFO, LVL_NOTICE, LVL_WARNING, LVL_ERROR, LVL_CRITICAL};
public:
    /**
     *  Switches Qpid Client API logging on.
     *  @param filename - the path to write to
     *  @param level - the loglevel
     *  @throw UsrException - if loglevel is wrong
     */
    static void enableLogging(const std::string &filename, LOG_LEVEL level)
    {
        enableLogging(filename, toString(level));
    }

    /**
     * Same as above but with level as a string.
     * @param filename - the path to write to
* @param level - "trace+", "debug+", "info+", "notice+", "warning+", "error+", "critical+"
     */
static void enableLogging(const std::string &filename, const std::string &level)
    {
        std::vector<const char*> arguments;
        arguments.push_back("this_argument_is_ignored");
        arguments.push_back("--log-to-file");
        arguments.push_back(filename.c_str());
        arguments.push_back("--log-enable");
        arguments.push_back(level.c_str());
        arguments.push_back(NULL);
qpid::messaging::Logger::configure(arguments.size()-1, &arguments[0]);
    }

    /**
     * converts given level to a string
     */
    static const std::string toString(LOG_LEVEL level)
    {
        switch (level) {
        case LVL_TRACE:    return "trace+";
        case LVL_DEBUG:   return "debug+";
        case LVL_INFO:      return "info+";
        case LVL_NOTICE:  return "notice+";
        case LVL_WARNING:  return "warning+";
        case LVL_ERROR:    return "error+";
        case LVL_CRITICAL: return "critical+";
        default:
            throw std::invalid_argument("wrong argument: " + level);
        }
    }
};

} // end namespace
#endif

Regards,
Andreas


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to