I am trying to deploy my application right now that uses Boost Log (Boost 1.58). This is a simple console application that runs on Windows 7. Logging works fine on my personal desktop.
However, when I deploy the application to a Win7 virtual machine, it crashes to my first log statement:
boost::log::sources::severity_logger<SeverityLevel> slg; BOOST_LOG_SEV(slg, SeverityLevel::Notification) << L"Application loaded";
A log directory is created, but the log file is never created and the application does not work.
I tried the journal directory in the% APPDATA% directory, as well as in my My Documents directory.
The odd thing: when I run the application as administrator, it works!
So this should be a permissions thing, but I have rights to these folders, so ...
Any ideas?
* MORE *
Here is the code to configure my registrar:
wstring appData = GetMyAppDataPath(); boost::shared_ptr< boost::log::sinks::synchronous_sink< boost::log::sinks::text_file_backend > > textFileSink(new boost::log::sinks::synchronous_sink< boost::log::sinks::text_file_backend >(to store rotated files boost::log::keywords::file_name = "log_%7N.log", // file name pattern boost::log::keywords::rotation_size = 16384 // rotation size, in characters )); // Set up where the rotated files will be stored textFileSink->locked_backend()->set_file_collector(boost::log::sinks::file::make_collector( boost::log::keywords::target = appData + L"\\logs", // where to store rotated files boost::log::keywords::max_size = 64 * 1024 * 1024, // maximum total size of the stored files, in bytes (64 MiB) boost::log::keywords::min_free_space = 100 * 1024 * 1024 // minimum free space on the drive, in bytes )); // Upon restart, scan the target directory for files matching the file_name pattern textFileSink->locked_backend()->scan_for_files(); // Set up the format for output to the text file. textFileSink->set_formatter(boost::log::expressions::stream << "[" << boost::log::expressions::attr< boost::posix_time::ptime >("TimeStamp") << " " << boost::log::expressions::attr< SeverityLevel, severity_tag >("Severity") << "] " << boost::log::expressions::message ); // Add it to the core boost::log::core::get()->add_sink(textFileSink);
which is mainly taken here: http://www.boost.org/doc/libs/1_58_0/libs/log/example/rotating_file/main.cpp .
* ALSO *
I added an exception handler to Boost Logger, adding:
boost::log::core::get()->set_exception_handler(boost::log::make_exception_handler< std::runtime_error, std::logic_error, std::exception >(pbb_boost_log_exception_handler()));
Then add a handler. When I run, I can catch the following exception before the crash:
std::exception: Failed to open file for writing: Input/output error: "C:\Program Files\My App\log_0000000.log"
WTF? I definitely set the location of the log file to appData , which I checked correctly. In addition, if I run this application as an administrator, the log file ends where I expect it (appdata folder). Therefore, it should simply create a temporary file in an executable location. Is this normal behavior? I canβt imagine that this is so ... so what did I do?