使用FastCGI的提升日志



我试图在我的FastCGI程序中使用boost日志,但看起来它们不能一起工作。

当我直接执行程序时,

/sample_log

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

当我使用spawn fcgi启动程序时,

sudo生成fcgi-p 8000-n sample_log

未记录任何消息。

以下是我正在使用的简单程序:

#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;
}

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

使用fcgi进行日志记录。

相关内容

  • 没有找到相关文章

最新更新