2015-04-08 34 views
0

我想在我的FastCGI程序中使用boost日志,但看起来他们不一起工作。FastCGI使用boost日志

当我执行直接的程序,

./sample_log

我可以看到登录登录到文件的消息。

当我使用产卵-FCGI启动该程序,

须藤产卵-FCGI -p 8000 -n sample_log

记录NO消息。

下面是简单的程序,我使用:

#include <boost/log/trivial.hpp> 
#include <boost/log/sources/severity_logger.hpp> 
#include <boost/log/utility/setup/file.hpp> 
#include <boost/log/utility/setup/console.hpp> 
#include <boost/log/utility/setup/from_stream.hpp> 
#include <boost/log/expressions.hpp> 
#include <boost/log/utility/setup/common_attributes.hpp> 
#include <boost/date_time/posix_time/posix_time_types.hpp> 
#include <boost/log/support/date_time.hpp> 
#include <boost/dynamic_bitset.hpp> 

#include <iostream> 
#include <fstream> 

using namespace std; 

namespace logging = boost::log; 
namespace attrs = boost::log::attributes; 
namespace sinks = boost::log::sinks; 
namespace expr = boost::log::expressions; 
namespace trivial = boost::log::trivial; 
namespace src = boost::log::sources; 
namespace keywords = boost::log::keywords; 

int main() 
{ 
    logging::add_file_log 
     (
      keywords::file_name = "sample.log", 
      // This makes the sink to write log records that look like this: 
      // 1: <normal> A normal severity message 
      // 2: <error> An error severity message 
      keywords::format = 
      (
       expr::stream 
       << expr::attr< unsigned int >("LineID") << " |" 
       << " [ " << expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%Y-%m-%d %H:%M:%S") << "]" 
       << ": <" << logging::trivial::severity << "> " 
       << expr::smessage 
      ) 
     ); 

    logging::add_common_attributes(); 

    using namespace logging::trivial; 
    src::severity_logger<severity_level> lg; 

    LOG(lg, trace) << "A trace severity message"; 
    LOG(lg, debug) << "A debug severity message"; 
    LOG(lg, info) << "An informational severity message"; 
    LOG(lg, warning) << "A warning severity message"; 
    LOG(lg, error) << "An error severity message"; 
    LOG(lg, fatal) << "A fatal severity message"; 

    FCGX_Request request; 

    FCGX_Init(); 
    FCGX_InitRequest(&request, 0, 0); 

    while (FCGX_Accept_r(&request) == 0) { 
     ...... 
    } 

    return; 
} 

回答

1

我必须设置 关键词:auto_flush = TRUE,

获得与FCGI记录工作。