You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by mc...@apache.org on 2004/08/11 21:01:15 UTC

cvs commit: logging-log4cxx/src outputdebugstringappender.cpp

mcatan      2004/08/11 12:01:15

  Modified:    msvc/dll dll.dsp dll.vcproj
               msvc/static static.cpp static.dsp static.vcproj
  Added:       include/log4cxx/nt outputdebugstringappender.h
               src      outputdebugstringappender.cpp
  Log:
  Issue : (LOGCXX-6) Win32 OutputDebugString
  
  Revision  Changes    Path
  1.1                  logging-log4cxx/include/log4cxx/nt/outputdebugstringappender.h
  
  http://cvs.apache.org/viewcvs/logging-log4cxx/include/log4cxx/nt/outputdebugstringappender.h?rev=1.1
  
  
  1.18      +1069 -1057logging-log4cxx/msvc/dll/dll.dsp
  
  http://cvs.apache.org/viewcvs/logging-log4cxx/msvc/dll/dll.dsp.diff?r1=1.17&r2=1.18
  
  
  1.9       +7 -1      logging-log4cxx/msvc/dll/dll.vcproj
  
  http://cvs.apache.org/viewcvs/logging-log4cxx/msvc/dll/dll.vcproj.diff?r1=1.8&r2=1.9
  
  
  1.5       +2 -0      logging-log4cxx/msvc/static/static.cpp
  
  http://cvs.apache.org/viewcvs/logging-log4cxx/msvc/static/static.cpp.diff?r1=1.4&r2=1.5
  
  
  1.7       +1029 -1021logging-log4cxx/msvc/static/static.dsp
  
  http://cvs.apache.org/viewcvs/logging-log4cxx/msvc/static/static.dsp.diff?r1=1.6&r2=1.7
  
  
  1.7       +3247 -3241logging-log4cxx/msvc/static/static.vcproj
  
  http://cvs.apache.org/viewcvs/logging-log4cxx/msvc/static/static.vcproj.diff?r1=1.6&r2=1.7
  
  
  1.1                  logging-log4cxx/src/outputdebugstringappender.cpp
  
  http://cvs.apache.org/viewcvs/logging-log4cxx/src/outputdebugstringappender.cpp?rev=1.1
  
  

Re: contribution offer: boost::format bindings for log4cxx

Posted by Curt Arnold <ca...@apache.org>.
On Aug 12, 2004, at 12:34 AM, troy d.straszheim wrote:

> Hi log4cxx --
>
> I have a feature written, I wonder if log4cxx wants it.
>
> there are the handy LOG4CXX_DEBUG(log, message) macros.  The thing 
> that gets me is that it won't do formatstring/args like printf.
> ...
>
> If there is any interest I'll send on the full implementation (it's 
> not very big)...
>
> -t
>
>

I don't think that is appropriate for the LOG4CXX_DEBUG and similar 
macros to be much more than a call to isDebugEnabled and forcedLog.  
Once usage patterns are established, then it might be appropriate to 
add additional macros perhaps like the one you suggested.  Until then, 
it might make a good FAQ.

Q: How can I used sprintf type formatting in log messages?

A: Use troy's LOG4CXX_DEBUG_FMT macros and boost


contribution offer: boost::format bindings for log4cxx

Posted by "troy d.straszheim" <tr...@resophonic.com>.
Hi log4cxx --

I have a feature written, I wonder if log4cxx wants it.

there are the handy LOG4CXX_DEBUG(log, message) macros.  The thing that 
gets me is that it won't do formatstring/args like printf.

One option:

#define LOG4CXX_DEBUG(logger, format, ...) { \
      if (logger->isDebugEnabled()) { \
      snprintf(logbuf_,logbuf_size_, format, ##__VA_ARGS__); \
      logger->forcedLog(::log4cxx::Level::DEBUG, logbuf_, __FILE__, 
__LINE__);}}

But this is problematic because it depends on the gnu preprocessor to 
properly handle cases where __VA_ARGS__ is empty (at least the gcc 
manual says this is a gnu extension to C.  Don't know if MS has adopted 
it or not.  Anyway, it's not ANSI.)  and it assumes that you have some 
logbuf_ and logbuf_size_ somewhere, not thread-safe.

So I put together a binding to boost::format that allows you to do this:

LOG4CXX_DEBUG(logger, "%d %d %d, it puts the lotion in the %s") % 1 % 2 
% 3 % "basket";

which also gets the __FILE__ and __LINE__ info through to the logger 
and involves some pretty slick glue code to format the string and pass 
it to the logger without any static buffers.
It also supports UDT's, since it's boost::format.  I notice that the 
library already uses (or can use) boost::regex, so I wonder how big of 
an issue that would be.  If you don't know what boost::format is, you 
have to check it out, it's very cool.  A typesafe printf for C++ that 
supports UDT's e.g.:

format("%s") % myclass;

will work if myclass has an associated insertion operator.   Also, the 
boost::format approach does not depend on anything non-ansi like the 
printf thing above, should work fine on windows (as far as I know).

The funamental motivation here is idea that that the calls to the 
logger should be as easy to use as possible, so that people write lots 
of debug level stuff, which makes great documentation, often better 
than comments.  There are a lot of people who just debug with printf 
out there, and if the logging statements are too hard to use, they'll 
just stick with printf, and then you have a mess (like the project I'm 
on on now), a mixture of printf, cout, cerr, and logging statements, 
egh.

If there is any interest I'll send on the full implementation (it's not 
very big)...

-t