Re: [Log4cplus-devel] Several problems with log4cplus on localized Windows
Logging Framework for C++
Brought to you by:
wilx
|
From: Václav Z. <v.h...@sh...> - 2011-08-14 18:45:19
|
Nikita Manovich wrote, On 5.8.2011 23:37:
> Hi,
>
> I integrated the library into a big project. It is very useful and
> cool library which helps to improve our logging significantly. But I
> found a real issue and it is critical for me.
> On Windows we use UNICODE version of the library and log4cplus
> doesn't work on localized Windows properly. First of all I was not
> able to open a file in case its path contained non-English characters.
I have fixed this on PRODUCTION_1_0_x branch. log4cplus will now use the
basic_fstream<>'s open()/ctor that takes wchar_t.
> After I fixed the bug I found another fundamental problem. I was not
> able to log a string with non-English characters (for example, a
> path). wfstream doesn't work correctly in this case with the default
> locale. I can't modify the global local because it can affect other
> parts of the product.
> The small patch below fixes these problems but I'm not sure that it
> is enough. I did analyze only a small part of the library
> (FileAppender). May be you know a better solution?
> In my code I wrote several additional lines (utf8_facet I got from boost):
> using namespace utf8_facet;
> std::locale utf8_locale(std::locale(), new utf8_codecvt_facet());
> pFileAppender->imbue(utf8_locale);
I have committed your patch extended with getloc() member function and
committed it to PRODUCTION_1_0_x branch in revision 1570.
>
>
> diff -ur log4cplus-1.0.4.orig//include/log4cplus/fileappender.h
> log4cplus-1.0.4/include/log4cplus/fileappender.h
> --- log4cplus-1.0.4.orig//include/log4cplus/fileappender.h
> 2010-05-28 13:06:51.000000000 +0400
> +++ log4cplus-1.0.4/include/log4cplus/fileappender.h 2011-08-06
> 00:25:50.230786400 +0400
> @@ -78,6 +78,10 @@
> // Dtor
> virtual ~FileAppender();
>
> + // Redefine default locale for output stream. It may be a good idea to
> + // provide UTF-8 locale in case UNICODE macro is defined.
> + virtual void imbue(std::locale const& loc);
> +
> // Methods
> virtual void close();
>
> diff -ur log4cplus-1.0.4.orig//src/fileappender.cxx
> log4cplus-1.0.4/src/fileappender.cxx
> --- log4cplus-1.0.4.orig//src/fileappender.cxx 2010-09-08
> 17:08:44.000000000 +0400
> +++ log4cplus-1.0.4/src/fileappender.cxx 2011-08-06
> 00:28:12.964058300 +0400
> @@ -333,7 +333,19 @@
> void
> FileAppender::open(std::ios::openmode mode)
> {
> +#if defined (_WIN32)
> + // MS SDK supports char and wchar_t. Don't try to convert wstring
> to string.
> + // It doesn't work. Need to reimplement working with non-english strings.
> + out.open(filename.c_str(), mode);
> +#else
> out.open(LOG4CPLUS_TSTRING_TO_STRING(filename).c_str(), mode);
> +#endif
> +}
> +
> +void
> +FileAppender::imbue(std::locale const& loc)
> +{
> + out.imbue(loc);
> }
>
> bool
> diff -ur log4cplus-1.0.4.orig//src/property.cxx log4cplus-1.0.4/src/property.cxx
> --- log4cplus-1.0.4.orig//src/property.cxx 2010-07-09
> 12:24:08.000000000 +0400
> +++ log4cplus-1.0.4/src/property.cxx 2011-08-05 15:27:55.395559800 +0400
> @@ -117,7 +117,13 @@
> if (inputFile.empty ())
> return;
>
> +#if defined (_WIN32)
> + // MS SDK supports char and wchar_t. Don't try to convert wstring
> to string.
> + // It doesn't work. Need to reimplement working with non-english strings.
> + tifstream file (inputFile.c_str());
> +#else
> tifstream file (LOG4CPLUS_TSTRING_TO_STRING(inputFile).c_str());
> +#endif
> init(file);
> }
>
>
Thank you.
--
wilx
|