小编Jua*_*olo的帖子

Boost.log:如何防止输出在使用add_file_log()函数时被复制到所有添加的流?

我使用该add_file_log()函数初始化将日志记录存储到文本文件中的日志记录接收器.当我定义几个接收器时,我观察到:

  • 为每个接收器创建一个文件.
  • 输出将复制到所有文件.

这是我的记录器:

class logger
{
public:
  logger(const logger&) =delete;
  logger(logger&&) =delete;
  logger& operator=(const logger&) =delete;
  logger& operator=(logger&&) =delete;

  static logger& get_instance(
    const std::string& file,
    bool console
  )
  {
      boost::log::register_simple_formatter_factory<
                                                    boost::log::trivial::severity_level,
                                                    char
                                                   >("Severity");

      std::string the_format = "[%TimeStamp%] (%LineID%) [%Severity%]: %Message%";

      if(!file.empty()) {
        boost::log::add_file_log(
          boost::log::keywords::file_name = file + "_%N.log",
          boost::log::keywords::rotation_size = 10 * 1024 * 1024,
          boost::log::keywords::time_based_rotation =
            boost::log::sinks::file::rotation_at_time_point(0, 0, 0),
          boost::log::keywords::auto_flush = true,
          //boost::log::keywords::open_mode = (std::ios::out | std::ios::app),
          boost::log::keywords::format = the_format
        );
      }

      boost::log::add_common_attributes();
      static logger instance{ …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-logging boost-log c++11

7
推荐指数
1
解决办法
2618
查看次数

如何使用Beast C ++库从HTTP重定向到HTTPS?

我正在研究Boost.Beast库。我尝试提出一个请求,其响应为:

HTTP/1.1 301 Moved Permanently
Cache-Control: public
Content-Type: text/html; charset=UTF-8
Location: https://www.example.com/target/xxx/
Run Code Online (Sandbox Code Playgroud)

然后,我尝试使用此位置字段发出请求,但收到错误的请求响应。

我该如何进行重定向?有例子吗?

这是我的代码:

boost::asio::io_service ios;
tcp::resolver resolver{ios};
tcp::socket socket{ios};
auto const lookup = resolver.resolve( tcp::resolver::query(host, port) );
boost::asio::connect(socket, lookup);

// Set up an HTTP GET request message
http::request<http::string_body> req{http::verb::get, target, 11};
req.set(http::field::host, host);
req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);

// Send the HTTP request to the remote host
http::write(socket, req);

// This buffer is used for reading and must be persisted
boost::beast::flat_buffer buffer;

// Declare a container to hold the response
http::response<http::dynamic_body> …
Run Code Online (Sandbox Code Playgroud)

c++ boost beast boost-beast

6
推荐指数
1
解决办法
1966
查看次数

如何创建std :: tuple的别名?

我正在学习C++,我想知道如何为它创建一个别名std::tuple.

我想做你可能做的事,std::tuple但使用另一个名字.可能吗?

谢谢.

c++ tuples std

4
推荐指数
1
解决办法
462
查看次数

哪个是初始化std :: map的最佳方法,它的值是std :: vector?

我有以下内容:

std::map<std::string, std::vector<std::string>> container;

要添加新项目,请执行以下操作:

void add(const std::string& value) {
    std::vector<std::string> values;
    values.push_back(value);
    container.insert(key, values);
}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来增加价值?

谢谢

c++ stl vector map c++11

3
推荐指数
1
解决办法
4102
查看次数

钥匙披风:ERR_TOO_MANY_REDIRECTS

我正在学习 Keycloak,但遇到以下问题。

我有一个通过 Keycloak(主应用程序)保护的 Java EE 应用程序。登录 keycloak 后,它访问另一个应用程序(应用程序示例,也受 keycloak 保护),该应用程序执行检查并根据结果返回主应用程序或显示错误。

问题是 app-example 重定向到 keycloak,keycloak 重定向回 app-example。最后,我收到错误:400 bad request。

在keycloak 前面,我有一个充当代理的Apache 服务器,所有连接都通过SSL。

第一次调用:

Request URL: https://localhost/app-example
Request Method: GET
Status Code: 302 Found
Remote Address: xxx.xxx.xxx.xxx:443
Referrer Policy: no-referrer-when-downgrade
Connection: Keep-Alive
Content-Length: 0
Date: Mon, 17 Dec 2018 14:09:07 GMT
Keep-Alive: timeout=5, max=96
Location: https://localhost/auth/realms/my-realm/protocol/openid-connect/auth?response_type=code&client_id=appexample&redirect_uri=https%3A%2F%2Flocalhost%2Fapp-example%2F&state=e327185a-6306-4124-b384-215954f51bb7&login=true&scope=openid
Server: Apache/2.4.10 (Debian) mod_jk/1.2.37 OpenSSL/1.0.1t
Set-Cookie: OAuth_Token_Request_State=e327185a-6306-4124-b384-215954f51bb7; Version=1; Secure; HttpOnly
Set-Cookie: JSESSIONID=AxzD3hq5sfv-SJdbSa7HDLJe1lBWC1ExBoy86TdR; path=/app-example
Strict-Transport-Security: max-age=15768000
X-Powered-By: Undertow/1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: es-ES,es;q=0.9 …
Run Code Online (Sandbox Code Playgroud)

keycloak

1
推荐指数
1
解决办法
4770
查看次数

标签 统计

c++ ×4

boost ×2

c++11 ×2

beast ×1

boost-beast ×1

boost-log ×1

boost-logging ×1

keycloak ×1

map ×1

std ×1

stl ×1

tuples ×1

vector ×1