[C++-sig] calling python logger module from C++

Petrucio petrucio at hoplon.com
Fri May 13 15:46:49 CEST 2005


I don't think it is possible.

I usually export 'instances' of my varargs functions to python. This could 
be an issue if the types of your args are also variable, like the standard 
printf-like functions.

You can in this case just export the most common uses, of a string and some 
other variable after, something like:

Your real vararged function:
virtual void Log( LogLevel level, std::wstring msg, ... ) = 0;

Exported 'instances'
virtual void Log( LogLevel level, std::wstring msg) = 0;
virtual void Log( LogLevel level, std::wstring msg, int int_arg) = 0;
virtual void Log( LogLevel level, std::wstring msg, std::wstring str_arg) = 0;

Although I can't immediately see the need for this, since that better place 
to format your string than python?

Beware of performance issues when using an inter-language polimorphic 
solution this this for something that will probably be called a lot like a 
logger.

Petrucio - Game Programmer
Hoplon Infotainment - www.taikodom.com.br

At 00:19 12/5/2005, you wrote:
>I've been wondering how best to provide support for calling my python logger
>(which uses the standard logger module) from within my C++ extensions built
>using Boost.Python. My first thought was to do this:
>
>enum LogLevel {
>   LogLevelCritical = 50,
>     LogLevelError = 40,
>     LogLevelWarning = 30,
>     LogLevelInfo = 20,
>     LogLevelDebug = 10
>};
>
>
>class PiLogger {
>public:
>
>   virtual void Log( LogLevel level, std::wstring msg ) = 0;
>
>};
>
>and then implement this class in python, setting it as a static variable in
>my C++. This works pretty well, but I'd like to be able to support format
>strings, which requires varargs. I couldn't figure out how to wrap a varargs
>function - is that even possible? If it's not, is there a better way to
>accomplish what I want?
>
>Thanks,
>
>Eric
>
>_______________________________________________
>C++-sig mailing list
>C++-sig at python.org
>http://mail.python.org/mailman/listinfo/c++-sig




More information about the Cplusplus-sig mailing list