[log] Wide Character Backend file problems

Hi, I was trying to create a log file with wide character support. Similar code with normal character support works well, where as for wide character support the log file itself is not getting created. Here is the code for both types. Can someone tell me, what am I missing with the wide character type. The code compiles, but the log file alone is not getting created when the program is run. //Wide Character version void Log_Init() { boost::function< void (std::wostream&, boost::log::wrecord const&) > formatter = boost::log::formatters::wstream << boost::log::formatters::date_time< boost::posix_time::ptime
(L"TimeStamp") << L" *" << boost::log::formatters::attr< int >(L"Severity") << L"* " << boost::log::formatters::wmessage();
boost::shared_ptr< sinks::synchronous_sink<boost::log::sinks::wtext_file_backend> > sink = boost::log::winit_log_to_file( keywords::file_name = L"C:\\BMR\\Logs\\bmr.log", // file name pattern keywords::rotation_size = 1 * 1024 * 1024, // rotate files every 1 MiB... keywords::open_mode = std::ios_base::app, keywords::auto_flush = true ); sink->locked_backend()->set_formatter(formatter); // Register common attributes boost::log::add_common_attributes(); } //Normal Character version void Log_Init() { boost::function< void (std::ostream&, boost::log::record const&) > formatter = boost::log::formatters::stream << boost::log::formatters::date_time< boost::posix_time::ptime
("TimeStamp") << " *" << boost::log::formatters::attr< int >("Severity") << "* " << boost::log::formatters::message();
boost::shared_ptr< sinks::synchronous_sink<boost::log::sinks::text_file_backend> > sink = boost::log::init_log_to_file( keywords::file_name = "C:\\BMR\\Logs\\bmr.log", // file name pattern keywords::rotation_size = 1 * 1024 * 1024, // rotate files every 1 MiB... keywords::open_mode = std::ios_base::app, keywords::auto_flush = true ); sink->locked_backend()->set_formatter(formatter); // Register common attributes boost::log::add_common_attributes(); }

On 08/15/2010 12:31 PM, Sivaram Kannan wrote:
Hi,
I was trying to create a log file with wide character support. Similar code with normal character support works well, where as for wide character support the log file itself is not getting created. Here is the code for both types. Can someone tell me, what am I missing with the wide character type. The code compiles, but the log file alone is not getting created when the program is run.
The add_common_attributes function works for narrow-character logging. Wide-character counterpart is wadd_common_attributes. This may be the culprit, since the standard attributes are not found by the formatter and thus no log record passes to the sink. You should be able to see that by exceptions that are thrown by the formatter, unless you suppress them.

Hi Andrey,
The add_common_attributes function works for narrow-character logging. Wide-character counterpart is wadd_common_attributes. This may be the culprit, since the standard attributes are not found by the formatter and thus no log record passes to the sink. You should be able to see that by exceptions that are thrown by the formatter, unless you suppress them.
Thanks for your prompt reply. I changed the code to wadd_common_attributes() but the log still did not get created. Am I right in mentioning the strings like TimeStamp with L"TimeStamp" and ketwords::file_name = L"C:\\test\\test.log" during initialization. One warning that I get during compilation is the following. Does the following relevant to my problem? I noticed I got the same warning when compiling for normal character as well. c:\documents and settings\administrator\my
documents\softwares\boost_1_43_0\boost\log\sources\global_logger_storage.hpp(122) : while compiling class template member function 'void boost::log_mt_nt5::sources::aux::logger_singleton<TagT>::init_instance(void)'
with [ TagT=bmr_log ] c:\documents and
settings\administrator\desktop\bzr-repo\cnbc\branch-refactoring-p1\cnbc\src\cnbc\logsink.h(36) : see reference to class template instantiation 'boost::log_mt_nt5::sources::aux::logger_singleton<TagT>' being compiled
with [ TagT=bmr_log ] boost::function< void (std::wostream&, boost::log::wrecord const&) >
formatter =
boost::log::formatters::wstream << boost::log::formatters::date_time< boost::posix_time::ptime
(L"TimeStamp") << L" *"
<< boost::log::formatters::attr< int >(L"Severity") << L"* " <<
boost::log::formatters::wmessage();
boost::shared_ptr<
sinks::synchronous_sink<boost::log::sinks::wtext_file_backend> > sink = boost::log::winit_log_to_file( keywords::file_name = L"C:\\test\\test.log", // file name
pattern
keywords::rotation_size = 1 * 1024 * 1024, // rotate files
every 1 MiB...
keywords::open_mode = std::ios_base::app, keywords::auto_flush = true );
sink->locked_backend()->set_formatter(formatter);
// Register common attributes
boost::log_mt_nt5::wadd_common_attributes(); Appreciate your helpful response. Thanks, Siva.

Hi Andrey, Adding to the earlier emails, can you give me a small working sample for "wtext_file_backend". I am not sure where exactly messing with my code here. This is my Global Macro declaration - this is where I think the warning is getting thrown, is there a problem here? BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(bmr_log, sources::severity_logger_mt<>) { Log_Init(); sources::severity_logger_mt<> lg; return lg; } Thanks, Siva.

On 08/15/2010 06:17 PM, Sivaram Kannan wrote:
Hi Andrey,
Adding to the earlier emails, can you give me a small working sample for "wtext_file_backend". I am not sure where exactly messing with my code here. This is my Global Macro declaration - this is where I think the warning is getting thrown, is there a problem here?
BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(bmr_log, sources::severity_logger_mt<>) { Log_Init();
sources::severity_logger_mt<> lg;
return lg; }
Logging sources should also be wide, so you should be using wseverity_logger_mt. I suggest you to build the library with the BOOST_LOG_USE_WCHAR_T macro defined. This will disable any narrow-character support in the library. Then you can try compiling your code and the parts that fail to link will highlight the places you have to modify in order to switch to wide character logging.

Hi,
Logging sources should also be wide, so you should be using wseverity_logger_mt.
I suggest you to build the library with the BOOST_LOG_USE_WCHAR_T macro defined. This will disable any narrow-character support in the library. Then you can try compiling your code and the parts that fail to link will highlight the places you have to modify in order to switch to wide character logging.
No luck with this too. I compiled with BOOST_LOG_USE_WCHAR_T. My program compiles without any problems but the log did not get created. Here is the actual warning that I am getting. Guess this is something to do with my global declaration. c:\documents and settings\administrator\my
documents\softwares\boost_1_43_0\boost\log\sources\global_logger_storage.hpp(136) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366)
: see declaration of 'sprintf'
c:\documents and settings\administrator\my
documents\softwares\boost_1_43_0\boost\log\sources\global_logger_storage.hpp(122) : while compiling class template member function 'void boost::log_mt_nt5::sources::aux::logger_singleton<TagT>::init_instance(void)'
with [ TagT=cli_log ] c:\documents and settings\administrator\my documents\visual studio
2008\projects\boostlog\boostlog\logsink.h(54) : see reference to class template instantiation 'boost::log_mt_nt5::sources::aux::logger_singleton<TagT>' being compiled
with [ TagT=cli_log ] Thanks, Siva.

Hi, wseverity_logger_mt did the trick. Did not notice you mentioned it earlier. Thanks a lot for your great response. Can you also suggest something about the warning? Thanks again. Siva. On Sun, Aug 15, 2010 at 11:37 PM, Sivaram Kannan <siva.devel@gmail.com>wrote:
Hi,
Logging sources should also be wide, so you should be using wseverity_logger_mt.
I suggest you to build the library with the BOOST_LOG_USE_WCHAR_T macro defined. This will disable any narrow-character support in the library. Then you can try compiling your code and the parts that fail to link will highlight the places you have to modify in order to switch to wide character logging.
No luck with this too. I compiled with BOOST_LOG_USE_WCHAR_T. My program compiles without any problems but the log did not get created. Here is the actual warning that I am getting. Guess this is something to do with my global declaration.
c:\documents and settings\administrator\my
documents\softwares\boost_1_43_0\boost\log\sources\global_logger_storage.hpp(136) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio
9.0\vc\include\stdio.h(366) : see declaration of 'sprintf'
c:\documents and settings\administrator\my
documents\softwares\boost_1_43_0\boost\log\sources\global_logger_storage.hpp(122) : while compiling class template member function 'void boost::log_mt_nt5::sources::aux::logger_singleton<TagT>::init_instance(void)'
with
[
TagT=cli_log
]
c:\documents and settings\administrator\my documents\visual studio
2008\projects\boostlog\boostlog\logsink.h(54) : see reference to class template instantiation 'boost::log_mt_nt5::sources::aux::logger_singleton<TagT>' being compiled
with
[
TagT=cli_log
]
Thanks, Siva.

On 08/15/2010 11:50 PM, Sivaram Kannan wrote:
Hi,
wseverity_logger_mt did the trick. Did not notice you mentioned it earlier. Thanks a lot for your great response. Can you also suggest something about the warning?
Well, you can define the suggested macro _CRT_SECURE_NO_WARNINGS or just suppress it altogether with a compiler switch. It should be taken care of in v2.

On 08/15/2010 06:00 PM, Sivaram Kannan wrote:
Thanks for your prompt reply. I changed the code to wadd_common_attributes() but the log still did not get created. Am I right in mentioning the strings like TimeStamp with L"TimeStamp" and ketwords::file_name = L"C:\\test\\test.log" during initialization.
The character type of attribute names indeed have to be the same as the logging character type. The file name can be specified either wide or narrow, regardless of the logging character type.
One warning that I get during compilation is the following. Does the following relevant to my problem? I noticed I got the same warning when compiling for normal character as well.
I think, you missed the warning message itself. The messages you posted only point to instantiations that led to the warning.
participants (2)
-
Andrey Semashev
-
Sivaram Kannan