Skip to content

Instantly share code, notes, and snippets.

@taxilian taxilian/Factory.cpp
Created Oct 15, 2011

What would you like to do?
Example of adding a file-based logging method
#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()));
// ...

This comment has been minimized.

Copy link
Owner Author

commented Nov 30, 2011

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


This comment has been minimized.

Copy link

commented Mar 22, 2012

Also need to #include "boost/thread.hpp" if it's not already present (can't add angles in comments it seems).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.