Created
October 15, 2011 04:14
-
-
Save taxilian/1289031 to your computer and use it in GitHub Desktop.
Example of adding a file-based logging method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/filesystem.hpp> | |
#include "SystemHelpers.h" | |
using namespace boost::filesystem; | |
/// ... | |
void getLoggingMethods( FB::Log::LogMethodList& outMethods ) | |
{ | |
path appDataPath = FB::System::getLocalAppDataPath("CompanyName"); | |
path logDirPath = appDataPath / "logs"; | |
if (exists(logDirPath) && is_directory(logDirPath)) { | |
std::stringstream ss; | |
time_t seconds = time(NULL); | |
boost::thread::id threadId = boost::this_thread::get_id(); | |
ss << seconds << "_" << threadId << ".log"; | |
path logPath = logDirPath / ss.str(); | |
fprintf(stderr, "logging to %s", logPath.string().c_str()); | |
outMethods.push_back(std::make_pair(FB::Log::LogMethod_File, logPath.string())); | |
} | |
#ifndef NDEBUG | |
outMethods.push_back(std::make_pair(FB::Log::LogMethod_Console, std::string())); | |
#endif | |
} | |
// ... |
Also need to #include "boost/thread.hpp" if it's not already present (can't add angles in comments it seems).
how about linux ?
got it, the reason was *.so has not be update.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this requires add_boost_library(filesystem) in your PluginConfig (because it relies on boost::filesystem). If you use this exactly as written logging to the console will be enabled for all debug builds and logging to file will be enabled if the directory exists.
On windows 7 this will be in the %USERPROFILE%\AppData\LocalLow\CompanyName\logs dir, on xp it will be %USERPROFILE%\Application Data\Local Settings\CompanyName\logs, and on Mac it'll be ~/Library/Application Support/CompanyName/logs